<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Standard Validation Classes - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.validate.set.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.validate.set.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.validate.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.validate.html">Zend_Validate</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.validate.validator_chains.html">Validator Chains</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.validate.set" class="section"><div class="info"><h1 class="title">Standard Validation Classes</h1></div>
    

    <p class="para">
        Zend Framework comes with a standard set of validation classes, which are ready for you to
        use.
    </p>

    <div class="section" id="zend.validate.set.alnum"><div class="info"><h1 class="title">Alnum</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Alnum</span> allows you to validate if a given value contains
        only alphabetical characters and digits. There is no length limitation for the input
        you want to validate.
    </p>

    <div class="section" id="zend.validate.set.alnum.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Alnum</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Alnum</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">allowWhiteSpace</span></em>: If whitespace
                    characters are allowed. This option defaults to <b><tt>FALSE</tt></b>
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.alnum.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            A basic example is the following one:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Alnum();
if ($validator-&gt;isValid(&#039;Abcd12&#039;)) {
    // value contains only allowed chars
} else {
    // false
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.alnum.whitespace"><div class="info"><h1 class="title">Using whitespaces</h1></div>
        

        <p class="para">
            Per default whitespaces are not accepted because they are not part of the alphabet.
            Still, there is a way to accept them as input. This allows to validate complete
            sentences or phrases.
        </p>

        <p class="para">
            To allow the usage of whitespaces you need to give the
            <span class="property">allowWhiteSpace</span> option. This can be done while creating an instance
            of the validator, or afterwards by using  <span class="methodname">setAllowWhiteSpace()</span>.
            To get the actual state you can use  <span class="methodname">getAllowWhiteSpace()</span>.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Alnum(array(&#039;allowWhiteSpace&#039; =&gt; true));
if ($validator-&gt;isValid(&#039;Abcd and 12&#039;)) {
    // value contains only allowed chars
} else {
    // false
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.alnum.languages"><div class="info"><h1 class="title">Using different languages</h1></div>
        

        <p class="para">
            When using <span class="classname">Zend_Validate_Alnum</span> then the language which the user
            sets within his browser will be used to set the allowed characters. This means when your
            user sets <em class="emphasis">de</em> for german then he can also enter characters like
            <em class="emphasis">ä</em>, <em class="emphasis">ö</em> and <em class="emphasis">ü</em> additionally
            to the characters from the english alphabet.
        </p>

        <p class="para">
            Which characters are allowed depends completly on the used language as every language
            defines it&#039;s own set of characters.
        </p>

        <p class="para">
            There are actually 3 languages which are not accepted in their own script. These
            languages are <em class="emphasis">korean</em>, <em class="emphasis">japanese</em> and
            <em class="emphasis">chinese</em> because this languages are using an alphabet where a
            single character is build by using multiple characters.
        </p>

        <p class="para">
            In the case you are using these languages, the input will only be validated by using
            the english alphabet.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.alpha"><div class="info"><h1 class="title">Alpha</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Alpha</span> allows you to validate if a given value contains
        only alphabetical characters. There is no length limitation for the input you want to
        validate. This validator is related to the <span class="classname">Zend_Validate_Alnum</span>
        validator with the exception that it does not accept digits.
    </p>

    <div class="section" id="zend.validate.set.alpha.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Alpha</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Alpha</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">allowWhiteSpace</span></em>: If whitespace
                    characters are allowed. This option defaults to <b><tt>FALSE</tt></b>
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.alpha.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            A basic example is the following one:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Alpha();
if ($validator-&gt;isValid(&#039;Abcd&#039;)) {
    // value contains only allowed chars
} else {
    // false
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.alpha.whitespace"><div class="info"><h1 class="title">Using whitespaces</h1></div>
        

        <p class="para">
            Per default whitespaces are not accepted because they are not part of the alphabet.
            Still, there is a way to accept them as input. This allows to validate complete
            sentences or phrases.
        </p>

        <p class="para">
            To allow the usage of whitespaces you need to give the
            <span class="property">allowWhiteSpace</span> option. This can be done while creating an instance
            of the validator, or afterwards by using  <span class="methodname">setAllowWhiteSpace()</span>.
            To get the actual state you can use  <span class="methodname">getAllowWhiteSpace()</span>.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Alpha(array(&#039;allowWhiteSpace&#039; =&gt; true));
if ($validator-&gt;isValid(&#039;Abcd and efg&#039;)) {
    // value contains only allowed chars
} else {
    // false
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.alpha.languages"><div class="info"><h1 class="title">Using different languages</h1></div>
        

        <p class="para">
            When using <span class="classname">Zend_Validate_Alpha</span> then the language which the user
            sets within his browser will be used to set the allowed characters. This means when your
            user sets <em class="emphasis">de</em> for german then he can also enter characters like
            <em class="emphasis">ä</em>, <em class="emphasis">ö</em> and <em class="emphasis">ü</em> additionally
            to the characters from the english alphabet.
        </p>

        <p class="para">
            Which characters are allowed depends completly on the used language as every language
            defines it&#039;s own set of characters.
        </p>

        <p class="para">
            There are actually 3 languages which are not accepted in their own script. These
            languages are <em class="emphasis">korean</em>, <em class="emphasis">japanese</em> and
            <em class="emphasis">chinese</em> because this languages are using an alphabet where a
            single character is build by using multiple characters.
        </p>

        <p class="para">
            In the case you are using these languages, the input will only be validated by using
            the english alphabet.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.barcode"><div class="info"><h1 class="title">Barcode</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Barcode</span> allows you to check if a given value can be
        represented as barcode.
    </p>

    <p class="para">
        <span class="classname">Zend_Validate_Barcode</span> supports multiple barcode standards and can be
        extended with proprietary barcode implementations very easily. The following barcode
        standards are supported:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <em class="emphasis">CODE25</em>: Often called &quot;two of five&quot; or &quot;Code25 Industrial&quot;.
            </p>

            <p class="para">
                This barcode has no length limitation. It supports only digits, and the last digit
                can be an optional checksum which is calculated with modulo 10. This standard is
                very old and nowadays not often used. Common usecases are within the industry.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">CODE25INTERLEAVED</em>: Often called &quot;Code 2 of 5 Interleaved&quot;.
            </p>

            <p class="para">
                This standard is a variant of CODE25. It has no length limitation, but it must
                contain an even amount of characters. It supports only digits, and the last digit
                can be an optional checksum which is calculated with modulo 10. It is used worldwide
                and common on the market.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">CODE39</em>: CODE39 is one of the oldest available codes.
            </p>

            <p class="para">
                This barcode has a variable length. It supports digits, upper cased alphabetical
                characters and 7 special characters like whitespace, point and dollar sign. It can
                have an optional checksum which is calculated with modulo 43. This standard is used
                worldwide and common within the industry.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">CODE39EXT</em>: CODE39EXT is an extension of CODE39.
            </p>

            <p class="para">
                This barcode has the same properties as CODE39. Additionally it allows the usage of
                all 128 ASCII characters. This standard is used worldwide and common within the
                industry.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">CODE93</em>: CODE93 is the successor of CODE39.
            </p>

            <p class="para">
                This barcode has a variable length. It supports digits, alphabetical characters
                and 7 special characters. It has an optional checksum which is calculated with
                modulo 47 and contains 2 characters. This standard produces a denser code than
                CODE39 and is more secure.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">CODE93EXT</em>: CODE93EXT is an extension of CODE93.
            </p>

            <p class="para">
                This barcode has the same properties as CODE93. Additionally it allows the usage of
                all 128 ASCII characters. This standard is used worldwide and common within the
                industry.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN2</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                These barcode must have 2 characters. It supports only digits and does not have a
                checksum. This standard is mainly used as addition to EAN13 (ISBN) when printed on
                books.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN5</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                These barcode must have 5 characters. It supports only digits and does not have a
                checksum. This standard is mainly used as addition to EAN13 (ISBN) when printed on
                books.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN8</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                These barcode can have 7 or 8 characters. It supports only digits. When it has a
                length of 8 characters it includes a checksum. This standard is used worldwide but
                has a very limited range. It can be found on small articles where a longer barcode
                could not be printed.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN12</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                This barcode must have a length of 12 characters. It supports only digits, and the
                last digit is always a checksum which is calculated with modulo 10. This standard is
                used within the USA and common on the market. It has been superceded by EAN13.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN13</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                This barcode must have a length of 13 characters. It supports only digits, and the
                last digit is always a checksum which is calculated with modulo 10. This standard is
                used worldwide and common on the market.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN14</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                This barcode must have a length of 14 characters. It supports only digits, and the
                last digit is always a checksum which is calculated with modulo 10. This standard is
                used worldwide and common on the market. It is the successor for EAN13.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">EAN18</em>: EAN is the shortcut for &quot;European Article Number&quot;.
            </p>

            <p class="para">
                This barcode must have a length of 18 characters. It support only digits. The last
                digit is always a checksum digit which is calculated with modulo 10. This code is
                often used for the identification of shipping containers.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">GTIN12</em>: GTIN is the shortcut for &quot;Global Trade Item Number&quot;.
            </p>

            <p class="para">
                This barcode uses the same standard as EAN12 and is its successor. It&#039;s commonly
                used within the USA.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">GTIN13</em>: GTIN is the shortcut for &quot;Global Trade Item Number&quot;.
            </p>

            <p class="para">
                This barcode uses the same standard as EAN13 and is its successor. It is used
                worldwide by industry.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">GTIN14</em>: GTIN is the shortcut for &quot;Global Trade Item Number&quot;.
            </p>

            <p class="para">
                This barcode uses the same standard as EAN14 and is its successor. It is used
                worldwide and common on the market.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">IDENTCODE</em>: Identcode is used by Deutsche Post and DHL. It&#039;s an
                specialized implementation of Code25.
            </p>

            <p class="para">
                This barcode must have a length of 12 characters. It supports only digits, and the
                last digit is always a checksum which is calculated with modulo 10. This standard is
                mainly used by the companies DP and DHL.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">INTELLIGENTMAIL</em>: Intelligent Mail is a postal barcode.
            </p>

            <p class="para">
                This barcode can have a length of 20, 25, 29 or 31 characters. It supports only
                digits, and contains no checksum. This standard is the successor of
                <acronym class="acronym">PLANET</acronym> and <acronym class="acronym">POSTNET</acronym>. It is mainly used by the
                United States Postal Services.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">ISSN</em>: <acronym class="acronym">ISSN</acronym> is the abbreviation for
                International Standard Serial Number.
            </p>

            <p class="para">
                This barcode can have a length of 8 or 13 characters. It supports only digits,
                and the last digit must be a checksum digit which is calculated with modulo 11.
                It is used worldwide for printed publications.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">ITF14</em>: ITF14 is the GS1 implementation of an Interleaved Two
                of Five bar code.
            </p>

            <p class="para">
                This barcode is a special variant of Interleaved 2 of 5. It must have a length of
                14 characters and is based on GTIN14. It supports only digits, and the last digit
                must be a checksum digit which is calculated with modulo 10. It is used worldwide
                and common within the market.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">LEITCODE</em>: Leitcode is used by Deutsche Post and DHL. It&#039;s an
                specialized implementation of Code25.
            </p>

            <p class="para">
                This barcode must have a length of 14 characters. It supports only digits, and the
                last digit is always a checksum which is calculated with modulo 10. This standard is
                mainly used by the companies DP and DHL.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">PLANET</em>: Planet is the abbreviation for Postal Alpha Numeric
                Encoding Technique.
            </p>

            <p class="para">
                This barcode can have a length of 12 or 14 characters. It supports only digits, and
                the last digit is always a checksum. This standard is mainly used by the United
                States Postal Services.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">POSTNET</em>: Postnet is used by the US Postal Service.
            </p>

            <p class="para">
                This barcode can have a length of 6, 7, 10 or 12 characters. It supports only
                digits, and the last digit is always a checksum. This standard is mainly used
                by the United States Postal Services.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">ROYALMAIL</em>: Royalmail is used by Royal Mail.
            </p>

            <p class="para">
                This barcode has no defined length. It supports digits, uppercased letters, and the
                last digit is always a checksum. This standard is mainly used by Royal Mail for
                their Cleanmail Service. It is also called <acronym class="acronym">RM4SCC</acronym>.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">SSCC</em>: SSCC is the shortcut for &quot;Serial Shipping Container
                Code&quot;.
            </p>

            <p class="para">
                This barcode is a variant of EAN barcode. It must have a length of 18 characters and
                supports only digits. The last digit must be a checksum digit which is calculated
                with modulo 10. It is commonly used by the transport industry.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">UPCA</em>: UPC is the shortcut for &quot;Univeral Product Code&quot;.
            </p>

            <p class="para">
                This barcode preceeded EAN13. It must have a length of 12 characters and supports
                only digits. The last digit must be a checksum digit which is calculated with
                modulo 10. It is commonly used within the USA.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <em class="emphasis">UPCE</em>: UPCE is the short variant from UPCA.
            </p>

            <p class="para">
                This barcode is a smaller variant of UPCA. It can have a length of 6, 7 or 8
                characters and supports only digits. When the barcode is 8 chars long it includes
                a checksum which is calculated with modulo 10. It is commonly used with small
                products where a UPCA barcode would not fit.
            </p>
        </li>
    </ul>

    <div class="section" id="zend.validate.set.barcode.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Barcode</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Barcode</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">adapter</span></em>: Sets the barcode adapter
                    which will be used. Supported are all above noted adapters. When using a self
                    defined adapter, then you have to set the complete classname.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">checksum</span></em>: <b><tt>TRUE</tt></b>
                    when the barcode should contain a checksum. The default value depends on the
                    used adapter. Note that some adapters don&#039;t allow to set this option.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">options</span></em>: Defines optional options for
                    a self written adapters.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.barcode.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            To validate if a given string is a barcode you just need to know its type. See the
            following example for an EAN13 barcode:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Barcode(&#039;EAN13&#039;);
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.barcode.checksum"><div class="info"><h1 class="title">Optional checksum</h1></div>
        

        <p class="para">
            Some barcodes can be provided with an optional checksum. These barcodes would be valid
            even without checksum. Still, when you provide a checksum, then you should also validate
            it. By default, these barcode types perform no checksum validation. By using the
            <span class="property">checksum</span> option you can define if the checksum will be validated or
            ignored.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Barcode(array(
    &#039;adapter&#039;  =&gt; &#039;EAN13&#039;,
    &#039;checksum&#039; =&gt; false,
));
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Reduced security by disabling checksum validation</b><br /></span>
            

            <p class="para">
                 By switching off checksum validation you will also reduce the security of the used
                 barcodes. Additionally you should note that you can also turn off the checksum
                 validation for those barcode types which must contain a checksum value. Barcodes
                 which would not be valid could then be returned as valid even if they are not.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.barcode.custom"><div class="info"><h1 class="title">Writing custom adapters</h1></div>
        

        <p class="para">
            You may write custom barcode validators for usage with
            <span class="classname">Zend_Validate_Barcode</span>; this is often necessary when dealing with
            proprietary barcode types. To write your own barcode validator, you need the following
            information.
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis">Length</em>: The length your barcode must have. It can have one
                    of the following values:
                </p>

                <ul class="itemizedlist">
                    <li class="listitem">
                        <p class="para">
                            <em class="emphasis">Integer</em>: A value greater 0, which means that the
                            barcode must have this length.
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            <em class="emphasis">-1</em>: There is no limitation for the length of this
                            barcode.
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            <em class="emphasis">&quot;even&quot;</em>: The length of this barcode must have a
                            even amount of digits.
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            <em class="emphasis">&quot;odd&quot;</em>: The length of this barcode must have a
                            odd amount of digits.
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            <em class="emphasis">array</em>: An array of integer values. The length of
                            this barcode must have one of the set array values.
                        </p>
                    </li>
                </ul>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">Characters</em>: A string which contains all allowed characters
                    for this barcode. Also the integer value 128 is allowed, which means the first
                    128 characters of the ASCII table.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">Checksum</em>: A string which will be used as callback for a
                    method which does the checksum validation.
                </p>
            </li>
        </ul>

        <p class="para">
            Your custom barcode validator must extend
            <span class="classname">Zend_Validate_Barcode_AdapterAbstract</span> or implement
            <span class="interface">Zend_Validate_Barcode_AdapterInterface</span>.
        </p>

        <p class="para">
            As an example, let&#039;s create a validator that expects an even number of characters that
            include all digits and the letters &#039;ABCDE&#039;, and which requires a checksum.
        </p>

        <pre class="programlisting brush: php">
class My_Barcode_MyBar extends Zend_Validate_Barcode_AdapterAbstract
{
    protected $_length     = &#039;even&#039;;
    protected $_characters = &#039;0123456789ABCDE&#039;;
    protected $_checksum   = &#039;_mod66&#039;;

    protected function _mod66($barcode)
    {
        // do some validations and return a boolean
    }
}

$valid = new Zend_Validate_Barcode(&#039;My_Barcode_MyBar&#039;);
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>

    </div>
</div>
    <div class="section" id="zend.validate.set.between"><div class="info"><h1 class="title">Between</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Between</span> allows you to validate if a given value is
        between two other values.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Zend_Validate_Between supports only number validation</b><br /></span>
        

        <p class="para">
            It should be noted that <span class="classname">Zend_Validate_Between</span> supports only the
            validation of numbers. Strings or dates can not be validated with this validator.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.between.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Between</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Between</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">inclusive</span></em>: Defines if the validation
                    is inclusive the minimum and maximum border values or exclusive. It defaults
                    to <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">max</span></em>: Sets the maximum border for the
                    validation.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">min</span></em>: Sets the minimum border for the
                    validation.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.between.basic"><div class="info"><h1 class="title">Default behaviour for Zend_Validate_Between</h1></div>
        

        <p class="para">
            Per default this validator checks if a value is between <span class="property">min</span> and
            <span class="property">max</span> where both border values are allowed as value.
        </p>

        <pre class="programlisting brush: php">
$valid  = new Zend_Validate_Between(array(&#039;min&#039; =&gt; 0, &#039;max&#039; =&gt; 10));
$value  = 10;
$result = $valid-&gt;isValid($value);
// returns true
</pre>


        <p class="para">
            In the above example the result is <b><tt>TRUE</tt></b> due to the reason that per
            default the search is inclusively the border values. This means in our case that any
            value from &#039;0&#039; to &#039;10&#039; is allowed. And values like &#039;-1&#039; and &#039;11&#039; will return
            <b><tt>FALSE</tt></b>.
        </p>
    </div>

    <div class="section" id="zend.validate.set.between.inclusively"><div class="info"><h1 class="title">Validation exclusive the border values</h1></div>
        

        <p class="para">
            Sometimes it is useful to validate a value by excluding the border values. See the
            following example:
        </p>

        <pre class="programlisting brush: php">
$valid  = new Zend_Validate_Between(
    array(
        &#039;min&#039; =&gt; 0,
        &#039;max&#039; =&gt; 10,
        &#039;inclusive&#039; =&gt; false
    )
);
$value  = 10;
$result = $valid-&gt;isValid($value);
// returns false
</pre>


        <p class="para">
            The example is almost equal to our first example but we excluded the border value. Now
            the values &#039;0&#039; and &#039;10&#039; are no longer allowed and will return
            <b><tt>FALSE</tt></b>.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.callback"><div class="info"><h1 class="title">Callback</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Callback</span> allows you to provide a callback with which to
        validate a given value.
    </p>

    <div class="section" id="zend.validate.set.callback.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Callback</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Callback</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">callback</span></em>: Sets the callback which will
                    be called for the validation.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">options</span></em>: Sets the additional options
                    which will be given to the callback.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.callback.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            The simplest usecase is to have a single function and use it as a callback. Let&#039;s expect
            we have the following function.
        </p>

        <pre class="programlisting brush: php">
function myMethod($value)
{
    // some validation
    return true;
}
</pre>


        <p class="para">
            To use it within <span class="classname">Zend_Validate_Callback</span> you just have to call it
            this way:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Callback(&#039;myMethod&#039;);
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.callback.closure"><div class="info"><h1 class="title">Usage with closures</h1></div>
        

        <p class="para">
            <acronym class="acronym">PHP</acronym> 5.3 introduces <a href="http://php.net/functions.anonymous" class="link external">&raquo; closures</a>, which are basically
            self-contained or <em class="emphasis">anonymous</em> functions. <acronym class="acronym">PHP</acronym>
            considers closures another form of callback, and, as such, may be used with
            <span class="classname">Zend_Validate_Callback</span>. As an example:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Callback(function($value){
    // some validation
    return true;
});

if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.callback.class"><div class="info"><h1 class="title">Usage with class-based callbacks</h1></div>
        

        <p class="para">
            Of course it&#039;s also possible to use a class method as callback. Let&#039;s expect we have
            the following class method:
        </p>

        <pre class="programlisting brush: php">
class MyClass
{
    public function myMethod($value)
    {
        // some validation
        return true;
    }
}
</pre>


        <p class="para">
            The definition of the callback is in this case almost the same. You have just to create
            an instance of the class before the method and create an array describing the callback:
        </p>

        <pre class="programlisting brush: php">
$object = new MyClass;
$valid = new Zend_Validate_Callback(array($object, &#039;myMethod&#039;));
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            You may also define a static method as a callback. Consider the following class
            definition and validator usage:
        </p>

        <pre class="programlisting brush: php">
class MyClass
{
    public static function test($value)
    {
        // some validation
        return true;
    }
}

$valid = new Zend_Validate_Callback(array(&#039;MyClass&#039;, &#039;test&#039;));
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            Finally, if you are using <acronym class="acronym">PHP</acronym> 5.3, you may define the magic method
             <span class="methodname">__invoke()</span> in your class. If you do so, simply providing an
            instance of the class as the callback will also work:
        </p>

        <pre class="programlisting brush: php">
class MyClass
{
    public function __invoke($value)
    {
        // some validation
        return true;
    }
}

$object = new MyClass();
$valid = new Zend_Validate_Callback($object);
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.callback.options2"><div class="info"><h1 class="title">Adding options</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_Callback</span> also allows the usage of options which
            are provided as additional arguments to the callback.
        </p>

        <p class="para">
            Consider the following class and method definition:
        </p>

        <pre class="programlisting brush: php">
class MyClass
{
    function myMethod($value, $option)
    {
        // some validation
        return true;
    }
}
</pre>


        <p class="para">
            There are two ways to inform the validator of additional options: pass them in the
            constructor, or pass them to the  <span class="methodname">setOptions()</span> method.
        </p>

        <p class="para">
            To pass them to the constructor, you would need to pass an array containing two keys,
            &quot;callback&quot; and &quot;options&quot;:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Callback(array(
    &#039;callback&#039; =&gt; array(&#039;MyClass&#039;, &#039;myMethod&#039;),
    &#039;options&#039;  =&gt; $option,
));

if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            Otherwise, you may pass them to the validator after instantiation:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Callback(array(&#039;MyClass&#039;, &#039;myMethod&#039;));
$valid-&gt;setOptions($option);

if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            When there are additional values given to  <span class="methodname">isValid()</span> then these
            values will be added immediately after <var class="varname">$value</var>.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Callback(array(&#039;MyClass&#039;, &#039;myMethod&#039;));
$valid-&gt;setOptions($option);

if ($valid-&gt;isValid($input, $additional)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            When making the call to the callback, the value to be validated will always be passed as
            the first argument to the callback followed by all other values given to
             <span class="methodname">isValid()</span>; all other options will follow it. The amount and
            type of options which can be used is not limited.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.creditcard"><div class="info"><h1 class="title">CreditCard</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_CreditCard</span> allows you to validate if a given value
        could be a credit card number.
    </p>

    <p class="para">
        A creditcard contains several items of metadata, including a hologram, account number, logo,
        expiration date, security code and the card holder name. The algorithms for verifying the
        combination of metadata are only known to the issuing company, and should be verified with
        them for purposes of payment. However, it&#039;s often useful to know whether or not a given
        number actually falls within the ranges of possible numbers <em class="emphasis">prior</em> to
        performing such verification, and, as such, <span class="classname">Zend_Validate_CreditCard</span>
        simply verifies that the credit card number provided is well-formed.
    </p>

    <p class="para">
        For those cases where you have a service that can perform comprehensive verification,
        <span class="classname">Zend_Validate_CreditCard</span> also provides the ability to attach a
        service callback to trigger once the credit card number has been deemed valid; this callback
        will then be triggered, and its return value will determine overall validity.
    </p>

    <p class="para">
        The following issuing institutes are accepted:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <em class="emphasis">American Express</em>
            </p>

            <p class="para">
                <em class="emphasis">China UnionPay</em>
            </p>

            <p class="para">
                <em class="emphasis">Diners Club Card Blanche</em>
            </p>

            <p class="para">
                <em class="emphasis">Diners Club International</em>
            </p>

            <p class="para">
                <em class="emphasis">Diners Club US &amp; Canada</em>
            </p>

            <p class="para">
                <em class="emphasis">Discover Card</em>
            </p>

            <p class="para">
                <em class="emphasis">JCB</em>
            </p>

            <p class="para">
                <em class="emphasis">Laser</em>
            </p>

            <p class="para">
                <em class="emphasis">Maestro</em>
            </p>

            <p class="para">
                <em class="emphasis">MasterCard</em>
            </p>

            <p class="para">
                <em class="emphasis">Solo</em>
            </p>

            <p class="para">
                <em class="emphasis">Visa</em>
            </p>

            <p class="para">
                <em class="emphasis">Visa Electron</em>
            </p>
        </li>
    </ul>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Invalid institutes</b><br /></span>
        

        <p class="para">
            The institutes <em class="emphasis">Bankcard</em> and <em class="emphasis">Diners Club
                enRoute</em> do not exist anymore. Therefore they are treated as invalid.
        </p>

        <p class="para">
            <em class="emphasis">Switch</em> has been rebranded to <em class="emphasis">Visa</em> and is
            therefore also treated as invalid.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.creditcard.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_CreditCard</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_CreditCard</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">service</span></em>: A callback to an online
                    service which will additionally be used for the validation.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">type</span></em>: The type of creditcard which
                    will be validated. See the below list of institutes for details.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.creditcard.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            There are several credit card institutes which can be validated by
            <span class="classname">Zend_Validate_CreditCard</span>. Per default, all known institutes will
            be accepted. See the folowing example:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_CreditCard();
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            The above example would validate against all known credit card institutes.
        </p>
    </div>

    <div class="section" id="zend.validate.set.creditcard.institute"><div class="info"><h1 class="title">Accepting defined credit cards</h1></div>
        

        <p class="para">
            Sometimes it is necessary to accept only defined credit card institutes instead of all;
            e.g., when you have a webshop which accepts only Visa and American Express cards.
            <span class="classname">Zend_Validate_CreditCard</span> allows you to do exactly this by
            limiting it to exactly these institutes.
        </p>

        <p class="para">
            To use a limitation you can either provide specific institutes at initiation, or
            afterwards by using  <span class="methodname">setType()</span>. Each can take several arguments.
        </p>

        <p class="para">
            You can provide a single institute:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_CreditCard(
    Zend_Validate_CreditCard::AMERICAN_EXPRESS
);
</pre>


        <p class="para">
            When you want to allow multiple institutes, then you can provide them as array:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_CreditCard(array(
    Zend_Validate_CreditCard::AMERICAN_EXPRESS,
    Zend_Validate_CreditCard::VISA
));
</pre>


        <p class="para">
            And as with all validators, you can also pass an associative array of options or an
            instance of <span class="classname">Zend_Config</span>. In this case you have to provide the
            institutes with the <span class="property">type</span> array key as simulated here:
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_CreditCard(array(
    &#039;type&#039; =&gt; array(Zend_Validate_CreditCard::AMERICAN_EXPRESS)
));
</pre>


        <table id="zend.validate.set.creditcard.institute.table" class="doctable table"><div class="info"><caption><b>Constants for credit card institutes</b></caption></div>
            

            
                <thead valign="middle">
                    <tr valign="middle">
                        <th>Institute</th>
                        <th>Constant</th>
                    </tr>

                </thead>


                <tbody valign="middle" class="tbody">
                    <tr valign="middle">
                        <td align="left"><em class="emphasis">American Express</em></td>
                        <td align="left"><b><tt>AMERICAN_EXPRESS</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">China UnionPay</em></td>
                        <td align="left"><b><tt>UNIONPAY</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Diners Club Card Blanche</em></td>
                        <td align="left"><b><tt>DINERS_CLUB</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Diners Club International</em></td>
                        <td align="left"><b><tt>DINERS_CLUB</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Diners Club US &amp; Canada</em></td>
                        <td align="left"><b><tt>DINERS_CLUB_US</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Discover Card</em></td>
                        <td align="left"><b><tt>DISCOVER</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">JCB</em></td>
                        <td align="left"><b><tt>JCB</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Laser</em></td>
                        <td align="left"><b><tt>LASER</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Maestro</em></td>
                        <td align="left"><b><tt>MAESTRO</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">MasterCard</em></td>
                        <td align="left"><b><tt>MASTERCARD</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Solo</em></td>
                        <td align="left"><b><tt>SOLO</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Visa</em></td>
                        <td align="left"><b><tt>VISA</tt></b></td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><em class="emphasis">Visa Electron</em></td>
                        <td align="left"><b><tt>VISA</tt></b></td>
                    </tr>

                </tbody>
            
        </table>


        <p class="para">
            You can also set or add institutes afterward instantiation by using the methods
             <span class="methodname">setType()</span>,  <span class="methodname">addType()</span> and
             <span class="methodname">getType()</span>.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_CreditCard();
$valid-&gt;setType(array(
    Zend_Validate_CreditCard::AMERICAN_EXPRESS,
    Zend_Validate_CreditCard::VISA
));
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Default institute</b><br /></span>
            

            <p class="para">
                When no institute is given at initiation then <b><tt>ALL</tt></b> will be
                used, which sets all institutes at once.
            </p>

            <p class="para">
                In this case the usage of  <span class="methodname">addType()</span> is useless because all
                institutes are already added.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.creditcard.servicecheck"><div class="info"><h1 class="title">Validation by using foreign APIs</h1></div>
        

        <p class="para">
            As said before <span class="classname">Zend_Validate_CreditCard</span> will only validate
            the credit card number. Fortunately, some institutes provide online
            <acronym class="acronym">API</acronym>s which can validate a credit card number by using algorithms
            which are not available to the public. Most of these services are paid services.
            Therefore, this check is deactivated per default.
        </p>

        <p class="para">
            When you have access to such an <acronym class="acronym">API</acronym>, then you can use it as an addon
            for <span class="classname">Zend_Validate_CreditCard</span> and increase the security of the
            validation.
        </p>

        <p class="para">
            To do so, you simply need to give a callback which will be called when the generic
            validation has passed. This prevents the <acronym class="acronym">API</acronym> from being called
            for invalid numbers, which increases the performance of the application.
        </p>

        <p class="para">
             <span class="methodname">setService()</span> sets a new service, and
             <span class="methodname">getService()</span> returns the set service. As a configuration
            option,
            you can give the array key &#039;<span class="property">service</span>&#039; at initiation. For details
            about possible options take a look into <a href="zend.validate.set.html#zend.validate.set.callback" class="link">Callback</a>.
        </p>

        <pre class="programlisting brush: php">
// Your service class
class CcService
{
    public function checkOnline($cardnumber, $types)
    {
        // some online validation
    }
}

// The validation
$service = new CcService();
$valid   = new Zend_Validate_CreditCard(Zend_Validate_CreditCard::VISA);
$valid-&gt;setService(array($service, &#039;checkOnline&#039;));
</pre>


        <p class="para">
            As you can see the callback method will be called with the creditcard number as the
            first parameter, and the accepted types as the second parameter.
        </p>
    </div>
</div>

    <div class="section" id="zend.validate.set.ccnum"><div class="info"><h1 class="title">Ccnum</h1></div>
        

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                The <span class="classname">Ccnum</span> validator has been deprecated in favor of the
                <span class="classname">CreditCard</span> validator. For security reasons you should use
                CreditCard instead of Ccnum.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.date"><div class="info"><h1 class="title">Date</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Date</span> allows you to validate if a given value contains
        a date. This validator validates also localized input.
    </p>

    <div class="section" id="zend.validate.set.date.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Date</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Date</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">format</span></em>: Sets the format which is used
                    to write the date.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">locale</span></em>: Sets the locale which will be
                    used to validate date values.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.date.basic"><div class="info"><h1 class="title">Default date validation</h1></div>
        

        <p class="para">
            The easiest way to validate a date is by using the default date format. It is used when
            no locale and no format has been given.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Date();

$validator-&gt;isValid(&#039;2000-10-10&#039;);   // returns true
$validator-&gt;isValid(&#039;10.10.2000&#039;); // returns false
</pre>


        <p class="para">
            The default date format for <span class="classname">Zend_Validate_Date</span> is &#039;yyyy-MM-dd&#039;.
        </p>
    </div>

    <div class="section" id="zend.validate.set.date.localized"><div class="info"><h1 class="title">Localized date validation</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_Date</span> validates also dates which are given in a
            localized format. By using the <span class="property">locale</span> option you can define the
            locale which the date format should use for validation.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Date(array(&#039;locale&#039; =&gt; &#039;de&#039;));

$validator-&gt;isValid(&#039;10.Feb.2010&#039;); // returns true
$validator-&gt;isValid(&#039;10.May.2010&#039;); // returns false
</pre>


        <p class="para">
            The <span class="property">locale</span> option sets the default date format. In the above
            example this is &#039;dd.MM.yyyy&#039; which is defined as default date format for &#039;de&#039;.
        </p>
    </div>

    <div class="section" id="zend.validate.set.date.formats"><div class="info"><h1 class="title">Self defined date validation</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_Date</span> supports also self defined date formats.
            When you want to validate such a date you can use the <span class="property">format</span>
            option.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Date(array(&#039;format&#039; =&gt; &#039;yyyy&#039;));

$validator-&gt;isValid(&#039;2010&#039;); // returns true
$validator-&gt;isValid(&#039;May&#039;);  // returns false
</pre>


        <p class="para">
            Of course you can combine <span class="property">format</span> and <span class="property">locale</span>.
            In this case you can also use localized month or daynames.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Date(array(&#039;format&#039; =&gt; &#039;yyyy MMMM&#039;, &#039;locale&#039; =&gt; &#039;de&#039;));

$validator-&gt;isValid(&#039;2010 Dezember&#039;); // returns true
$validator-&gt;isValid(&#039;2010 June&#039;);     // returns false
</pre>

    </div>
</div>
    <div class="section" id="zend.validate.Db"><div class="info"><h1 class="title">Db_RecordExists and Db_NoRecordExists</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Db_RecordExists</span> and
        <span class="classname">Zend_Validate_Db_NoRecordExists</span> provide a means to test
        whether a record exists in a given table of a database, with a given
        value.
    </p>

    <div class="section" id="zend.validate.set.db.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Db_*</h1></div>
        

        <p class="para">
            The following options are supported for
            <span class="classname">Zend_Validate_Db_NoRecordExists</span> and
            <span class="classname">Zend_Validate_Db_RecordExists</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">adapter</span></em>: The database adapter which
                    will be used for the search.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">exclude</span></em>: Sets records which will be
                    excluded from the search.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">field</span></em>: The database field within this
                    table which will be searched for the record.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">schema</span></em>: Sets the schema which will be
                    used for the search.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">table</span></em>: The table which will be
                    searched for the record.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.db.basic-usage"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            An example of basic usage of the validators:
        </p>

        <pre class="programlisting brush: php">
//Check that the email address exists in the database
$validator = new Zend_Validate_Db_RecordExists(
    array(
        &#039;table&#039; =&gt; &#039;users&#039;,
        &#039;field&#039; =&gt; &#039;emailaddress&#039;
    )
);

if ($validator-&gt;isValid($emailaddress)) {
    // email address appears to be valid
} else {
    // email address is invalid; print the reasons
    foreach ($validator-&gt;getMessages() as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            The above will test that a given email address is in the database
            table. If no record is found containing the value of
            <var class="varname">$emailaddress</var> in the specified column, then an error
            message is displayed.
        </p>

        <pre class="programlisting brush: php">
//Check that the username is not present in the database
$validator = new Zend_Validate_Db_NoRecordExists(
    array(
        &#039;table&#039; =&gt; &#039;users&#039;,
        &#039;field&#039; =&gt; &#039;username&#039;
    )
);
if ($validator-&gt;isValid($username)) {
    // username appears to be valid
} else {
    // username is invalid; print the reason
    $messages = $validator-&gt;getMessages();
    foreach ($messages as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            The above will test that a given username is not in the database
            table. If a record is found containing the value of
            <var class="varname">$username</var> in the specified column, then an error
            message is displayed.
        </p>
    </div>

    <div class="section" id="zend.validate.db.excluding-records"><div class="info"><h1 class="title">Excluding records</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_Db_RecordExists</span> and
            <span class="classname">Zend_Validate_Db_NoRecordExists</span> also provide a means
            to test the database, excluding a part of the table, either by
            providing a where clause as a string, or an array with the keys
            &quot;field&quot; and &quot;value&quot;.
        </p>

        <p class="para">
            When providing an array for the exclude clause, the <em class="emphasis">!=</em>
            operator is used, so you can check the rest of a table for a value
            before altering a record (for example on a user profile form)
        </p>

        <pre class="programlisting brush: php">
//Check no other users have the username
$user_id   = $user-&gt;getId();
$validator = new Zend_Validate_Db_NoRecordExists(
    array(
        &#039;table&#039; =&gt; &#039;users&#039;,
        &#039;field&#039; =&gt; &#039;username&#039;,
        &#039;exclude&#039; =&gt; array(
            &#039;field&#039; =&gt; &#039;id&#039;,
            &#039;value&#039; =&gt; $user_id
        )
    )
);

if ($validator-&gt;isValid($username)) {
    // username appears to be valid
} else {
    // username is invalid; print the reason
    $messages = $validator-&gt;getMessages();
    foreach ($messages as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            The above example will check the table to ensure no records other
            than the one where <strong class="command">id = $user_id</strong> contains the value
            $username.
        </p>

        <p class="para">
            You can also provide a string to the exclude clause so you can use
            an operator other than <em class="emphasis">!=</em>. This can be useful for
            testing against composite keys.
        </p>

        <pre class="programlisting brush: php">
$email     = &#039;user@example.com&#039;;
$clause    = $db-&gt;quoteInto(&#039;email = ?&#039;, $email);
$validator = new Zend_Validate_Db_RecordExists(
    array(
        &#039;table&#039;   =&gt; &#039;users&#039;,
        &#039;field&#039;   =&gt; &#039;username&#039;,
        &#039;exclude&#039; =&gt; $clause
    )
);

if ($validator-&gt;isValid($username)) {
    // username appears to be valid
} else {
    // username is invalid; print the reason
    $messages = $validator-&gt;getMessages();
    foreach ($messages as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            The above example will check the &#039;users&#039; table
            to ensure that only a record with both the username
            <var class="varname">$username</var> and with the email
            <var class="varname">$email</var> is valid.
        </p>
    </div>

    <div class="section" id="zend.validate.db.database-adapters"><div class="info"><h1 class="title">Database Adapters</h1></div>
        

        <p class="para">
            You can also specify an adapter. This will allow you to work with
            applications using multiple database adapters, or where you have not
            set a default adapter. As in the example below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Db_RecordExists(
    array(
        &#039;table&#039; =&gt; &#039;users&#039;,
        &#039;field&#039; =&gt; &#039;id&#039;,
        &#039;adapter&#039; =&gt; $dbAdapter
    )
);
</pre>

    </div>

    <div class="section" id="zend.validate.db.database-schemas"><div class="info"><h1 class="title">Database Schemas</h1></div>
        

        <p class="para">
            You can specify a schema within your database for adapters such as
            PostgreSQL and DB/2 by simply supplying an array with
            <span class="property">table</span> and <span class="property">schema</span> keys. As in the example
            below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Db_RecordExists(
    array(
        &#039;table&#039;  =&gt; &#039;users&#039;,
        &#039;schema&#039; =&gt; &#039;my&#039;,
        &#039;field&#039;  =&gt; &#039;id&#039;
    )
);
</pre>

    </div>
</div>
    <div class="section" id="zend.validate.set.digits"><div class="info"><h1 class="title">Digits</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Digits</span> validates if a given value contains only digits.
    </p>

    <div class="section" id="zend.validate.set.digits.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Digits</h1></div>
        

        <p class="para">
            There are no additional options for <span class="classname">Zend_Validate_Digits</span>:
        </p>
    </div>

    <div class="section" id="zend.validate.set.digits.basic"><div class="info"><h1 class="title">Validating digits</h1></div>
        

        <p class="para">
            To validate if a given value contains only digits and no other characters, simply call
            the validator like shown in this example:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Digits();

$validator-&gt;isValid(&quot;1234567890&quot;); // returns true
$validator-&gt;isValid(1234);         // returns true
$validator-&gt;isValid(&#039;1a234&#039;);      // returns false
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Validating numbers</b><br /></span>
            

            <p class="para">
                When you want to validate numbers or numeric values, be aware that this validator
                only validates digits. This means that any other sign like a thousand separator or
                a comma will not pass this validator. In this case you should use
                <span class="classname">Zend_Validate_Int</span> or
                <span class="classname">Zend_Validate_Float</span>.
            </p>
        </p></blockquote>
    </div>
</div>
    <div class="section" id="zend.validate.set.email_address"><div class="info"><h1 class="title">EmailAddress</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_EmailAddress</span> allows you to validate an email address.
        The validator first splits the email address on local-part @ hostname and attempts to match
        these against known specifications for email addresses and hostnames.
    </p>

    <div class="section" id="zend.validate.set.email_address.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            A basic example of usage is below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress();
if ($validator-&gt;isValid($email)) {
    // email appears to be valid
} else {
    // email is invalid; print the reasons
    foreach ($validator-&gt;getMessages() as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            This will match the email address <var class="varname">$email</var> and on failure populate
             <span class="methodname">getMessages()</span> with useful error messages.
        </p>
    </div>

    <div class="section" id="zend.validate.set.email_address.options"><div class="info"><h1 class="title">Options for validating Email Addresses</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_EmailAddress</span> supports several options which can
            either be set at initiation, by giving an array with the related options, or
            afterwards, by using  <span class="methodname">setOptions()</span>. The following options are
            supported:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">allow</span></em>: Defines which type of domain
                    names are accepted. This option is used in conjunction with the hostname option
                    to set the hostname validator. For more informations about possible values of
                    this option, look at <a href="zend.validate.set.html#zend.validate.set.hostname" class="link">Hostname</a>
                    and possible <b><tt>ALLOW</tt></b>* constants. This option defaults to
                    <b><tt>ALLOW_DNS</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">deep</span></em>: Defines if the servers MX
                    records should be verified by a deep check. When this option is set to
                    <b><tt>TRUE</tt></b> then additionally to MX records also the A, A6 and
                    <b><tt>AAAA</tt></b> records are used to verify if the server accepts
                    emails. This option defaults to <b><tt>FALSE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">domain</span></em>: Defines if the domain part
                    should be checked. When this option is set to <b><tt>FALSE</tt></b>, then
                    only the local part of the email address will be checked. In this case the
                    hostname validator will not be called. This option defaults to
                    <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">hostname</span></em>: Sets the hostname validator
                    with which the domain part of the email address will be validated.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">mx</span></em>: Defines if the MX records from the
                    server should be detected. If this option is defined to
                    <b><tt>TRUE</tt></b> then the MX records are used to verify if the server
                    accepts emails. This option defaults to <b><tt>FALSE</tt></b>.
                </p>
            </li>
        </ul>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress();
$validator-&gt;setOptions(array(&#039;domain&#039; =&gt; false));
</pre>

    </div>

    <div class="section" id="zend.validate.set.email_address.complexlocal"><div class="info"><h1 class="title">Complex local parts</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_EmailAddress</span> will match any valid email address
            according to RFC2822. For example, valid emails include
            <em class="emphasis">bob@domain.com</em>, <em class="emphasis">bob+jones@domain.us</em>,
            <em class="emphasis">&quot;bob@jones&quot;@domain.com</em> and
            <em class="emphasis">&quot;bob jones&quot;@domain.com</em>.
        </p>

        <p class="para">
            Some obsolete email formats will not currently validate (e.g. carriage returns or a
            &quot;\&quot; character in an email address).
        </p>
    </div>

    <div class="section" id="zend.validate.set.email_address.purelocal"><div class="info"><h1 class="title">Validating only the local part</h1></div>
        

        <p class="para">
            If you need <span class="classname">Zend_Validate_EmailAddress</span> to check only the local
            part of an email address, and want to disable validation of the hostname, you can
            set the <span class="property">domain</span> option to <b><tt>FALSE</tt></b>. This forces
            <span class="classname">Zend_Validate_EmailAddress</span> not to validate the hostname part of
            the email address.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress();
$validator-&gt;setOptions(array(&#039;domain&#039; =&gt; FALSE));
</pre>

    </div>

    <div class="section" id="zend.validate.set.email_address.hostnametype"><div class="info"><h1 class="title">Validating different types of hostnames</h1></div>
        

        <p class="para">
            The hostname part of an email address is validated against <a href="zend.validate.set.html#zend.validate.set.hostname" class="link">
                <span class="classname">Zend_Validate_Hostname</span></a>. By default
            only DNS hostnames of the form <var class="filename">domain.com</var> are accepted, though if
            you wish you can accept IP addresses and Local hostnames too.
        </p>

        <p class="para">
            To do this you need to instantiate <span class="classname">Zend_Validate_EmailAddress</span>
            passing a parameter to indicate the type of hostnames you want to accept. More details
            are included in <span class="classname">Zend_Validate_Hostname</span>, though an example of how
            to accept both DNS and Local hostnames appears below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress(
                    Zend_Validate_Hostname::ALLOW_DNS |
                    Zend_Validate_Hostname::ALLOW_LOCAL);
if ($validator-&gt;isValid($email)) {
    // email appears to be valid
} else {
    // email is invalid; print the reasons
    foreach ($validator-&gt;getMessages() as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.email_address.checkacceptance"><div class="info"><h1 class="title">Checking if the hostname actually accepts email</h1></div>
        

        <p class="para">
            Just because an email address is in the correct format, it doesn&#039;t necessarily mean
            that email address actually exists. To help solve this problem, you can use MX
            validation to check whether an MX (email) entry exists in the DNS record for the
            email&#039;s hostname. This tells you that the hostname accepts email, but doesn&#039;t tell you
            the exact email address itself is valid.
        </p>

        <p class="para">
            MX checking is not enabled by default. To enable MX checking you can pass a second
            parameter to the <span class="classname">Zend_Validate_EmailAddress</span> constructor.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress(
    array(
        &#039;allow&#039; =&gt; Zend_Validate_Hostname::ALLOW_DNS,
        &#039;mx&#039;    =&gt; true
    )
);
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>MX Check under Windows</b><br /></span>
            

            <p class="para">
                Within Windows environments MX checking is only available when
                <acronym class="acronym">PHP</acronym> 5.3 or above is used. Below <acronym class="acronym">PHP</acronym> 5.3 MX
                checking will not be used even if it&#039;s activated within the options.
            </p>
        </p></blockquote>

        <p class="para">
            Alternatively you can either pass <b><tt>TRUE</tt></b> or
            <b><tt>FALSE</tt></b> to  <span class="methodname">setValidateMx()</span> to enable
            or disable MX validation.
        </p>

        <p class="para">
            By enabling this setting network functions will be used to check for the presence of an
            MX record on the hostname of the email address you wish to validate. Please be aware
            this will likely slow your script down.
        </p>

        <p class="para">
            Sometimes validation for MX records returns <b><tt>FALSE</tt></b>, even if emails
            are accepted. The reason behind this behaviour is, that servers can accept emails even
            if they do not provide a MX record. In this case they can provide A, A6 or
            <b><tt>AAAA</tt></b> records. To allow
            <span class="classname">Zend_Validate_EmailAddress</span> to check also for these other records,
            you need to set deep MX validation. This can be done at initiation by setting the
            <span class="property">deep</span> option or by using  <span class="methodname">setOptions()</span>.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress(
    array(
        &#039;allow&#039; =&gt; Zend_Validate_Hostname::ALLOW_DNS,
        &#039;mx&#039;    =&gt; true,
        &#039;deep&#039;  =&gt; true
    )
);
</pre>


        <div class="warning"><b class="warning">Warning</b><div class="info"><h1 class="title">Performance warning</h1></div>
            

            <p class="para">
                You should be aware that enabling MX check will slow down you script because of the
                used network functions. Enabling deep check will slow down your script even more as
                it searches the given server for 3 additional types.
            </p>
        </div>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Disallowed IP addresses</b><br /></span>
            

            <p class="para">
                You should note that MX validation is only accepted for external servers. When deep
                MX validation is enabled, then local IP addresses like <strong class="command">192.168.*</strong>
                or <strong class="command">169.254.*</strong> are not accepted.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.email_address.validateidn"><div class="info"><h1 class="title">Validating International Domains Names</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_EmailAddress</span> will also match international
            characters that exist in some domains. This is known as International Domain Name (IDN)
            support. This is enabled by default, though you can disable this by changing the
            setting via the internal <span class="classname">Zend_Validate_Hostname</span> object that
            exists within <span class="classname">Zend_Validate_EmailAddress</span>.
        </p>

        <pre class="programlisting brush: php">
$validator-&gt;getHostnameValidator()-&gt;setValidateIdn(false);
</pre>


        <p class="para">
            More information on the usage of  <span class="methodname">setValidateIdn()</span> appears in
            the <span class="classname">Zend_Validate_Hostname</span> documentation.
        </p>

        <p class="para">
            Please note IDNs are only validated if you allow DNS hostnames to be validated.
        </p>
    </div>

    <div class="section" id="zend.validate.set.email_address.validatetld"><div class="info"><h1 class="title">Validating Top Level Domains</h1></div>
        

        <p class="para">
            By default a hostname will be checked against a list of known TLDs. This is enabled by
            default, though you can disable this by changing the setting via the internal
            <span class="classname">Zend_Validate_Hostname</span> object that exists within
            <span class="classname">Zend_Validate_EmailAddress</span>.
        </p>

        <pre class="programlisting brush: php">
$validator-&gt;getHostnameValidator()-&gt;setValidateTld(false);
</pre>


        <p class="para">
            More information on the usage of  <span class="methodname">setValidateTld()</span> appears in
            the <span class="classname">Zend_Validate_Hostname</span> documentation.
        </p>

        <p class="para">
            Please note TLDs are only validated if you allow DNS hostnames to be validated.
        </p>
    </div>

    <div class="section" id="zend.validate.set.email_address.setmessage"><div class="info"><h1 class="title">Setting messages</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_EmailAddress</span> makes also use of
            <span class="classname">Zend_Validate_Hostname</span> to check the hostname part of a given
            email address. As with Zend Framework 1.10 you can simply set messages for
            <span class="classname">Zend_Validate_Hostname</span> from within
            <span class="classname">Zend_Validate_EmailAddress</span>.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_EmailAddress();
$validator-&gt;setMessages(
    array(
        Zend_Validate_Hostname::UNKNOWN_TLD =&gt; &quot;I don&#039;t know the TLD you gave&quot;
    )
);
</pre>


        <p class="para">
            Before Zend Framework 1.10 you had to attach the messages to your own
            <span class="classname">Zend_Validate_Hostname</span>, and then set this validator within
            <span class="classname">Zend_Validate_EmailAddress</span> to get your own messages returned.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.float"><div class="info"><h1 class="title">Float</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Float</span> allows you to validate if a given value contains
        a floating-point value. This validator validates also localized input.
    </p>

    <div class="section" id="zend.validate.set.float.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Float</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Float</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">locale</span></em>: Sets the locale which will be
                    used to validate localized float values.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.float.basic"><div class="info"><h1 class="title">Simple float validation</h1></div>
        

        <p class="para">
            The simplest way to validate a float is by using the system settings. When no option
            is used, the environment locale is used for validation:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Float();

$validator-&gt;isValid(1234.5);   // returns true
$validator-&gt;isValid(&#039;10a01&#039;); // returns false
$validator-&gt;isValid(&#039;1,234.5&#039;); // returns true
</pre>


        <p class="para">
            In the above example we expected that our environment is set to &quot;en&quot; as locale.
        </p>
    </div>

    <div class="section" id="zend.validate.set.float.localized"><div class="info"><h1 class="title">Localized float validation</h1></div>
        

        <p class="para">
            Often it&#039;s useful to be able to validate also localized values. Float values are often
            written different in other countries. For example using english you will write &quot;1.5&quot;.
            In german you may write &quot;1,5&quot; and in other languages you may use grouping.
        </p>

        <p class="para">
            <span class="classname">Zend_Validate_Float</span> is able to validate such notations. But it is
            limited to the locale you set. See the following code:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Float(array(&#039;locale&#039; =&gt; &#039;de&#039;));

$validator-&gt;isValid(1234.5); // returns true
$validator-&gt;isValid(&quot;1 234,5&quot;); // returns false
$validator-&gt;isValid(&quot;1.234&quot;); // returns true
</pre>


        <p class="para">
            As you can see, by using a locale, your input is validated localized. Using a different
            notation you get a <b><tt>FALSE</tt></b> when the locale forces a different
            notation.
        </p>

        <p class="para">
            The locale can also be set afterwards by using  <span class="methodname">setLocale()</span> and
            retrieved by using  <span class="methodname">getLocale()</span>.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.greaterthan"><div class="info"><h1 class="title">GreaterThan</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_GreaterThan</span> allows you to validate if a given value is
        greater than a minimum border value.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Zend_Validate_GreaterThan supports only number validation</b><br /></span>
        

        <p class="para">
            It should be noted that <span class="classname">Zend_Validate_GreaterThan</span> supports only
            the validation of numbers. Strings or dates can not be validated with this validator.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.greaterthan.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_GreaterThan</h1></div>
        

        <p class="para">
            The following options are supported for
            <span class="classname">Zend_Validate_GreaterThan</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">min</span></em>: Sets the minimum allowed value.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.greaterthan.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            To validate if a given value is greater than a defined border simply use the following
            example.
        </p>

        <pre class="programlisting brush: php">
$valid  = new Zend_Validate_GreaterThan(array(&#039;min&#039; =&gt; 10));
$value  = 10;
$return = $valid-&gt;isValid($value);
// returns true
</pre>


        <p class="para">
            The above example returns <b><tt>TRUE</tt></b> for all values which are equal to 10
            or greater than 10.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.hex"><div class="info"><h1 class="title">Hex</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Hex</span> allows you to validate if a given value contains
        only hexadecimal characters. These are all characters from <em class="emphasis">0 to 9</em> and
        <em class="emphasis">A to F</em> case insensitive. There is no length limitation for the input
        you want to validate.
    </p>

    <pre class="programlisting brush: php">
$validator = new Zend_Validate_Hex();
if ($validator-&gt;isValid(&#039;123ABC&#039;)) {
    // value contains only hex chars
} else {
    // false
}
</pre>


    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Invalid characters</b><br /></span>
        

        <p class="para">
            All other characters will return false, including whitespace and decimal point. Also
            unicode zeros and numbers from other scripts than latin will not be treaten as valid.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.hex.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Hex</h1></div>
        

        <p class="para">
            There are no additional options for <span class="classname">Zend_Validate_Hex</span>:
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.hostname"><div class="info"><h1 class="title">Hostname</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Hostname</span> allows you to validate a hostname against a
        set of known specifications. It is possible to check for three different types of hostnames:
        a <acronym class="acronym">DNS</acronym> Hostname (i.e. <var class="filename">domain.com</var>), IP address (i.e.
        1.2.3.4), and Local hostnames (i.e. localhost). By default only <acronym class="acronym">DNS</acronym>
        hostnames are matched.
    </p>

    <div class="section" id="zend.validate.set.hostname.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Hostname</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Hostname</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">allow</span></em>: Defines the sort of hostname
                    which is allowed to be used. See <a href="zend.validate.set.html#zend.validate.set.hostname.types" class="link">Hostname types</a> for
                    details.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">idn</span></em>: Defines if <acronym class="acronym">IDN</acronym>
                    domains are allowed or not. This option defaults to <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">ip</span></em>: Allows to define a own IP
                    validator. This option defaults to a new instance of
                    <span class="classname">Zend_Validate_Ip</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">tld</span></em>: Defines if
                    <acronym class="acronym">TLD</acronym>s are validated. This option defaults to
                    <b><tt>TRUE</tt></b>.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.hostname.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            A basic example of usage is below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Hostname();
if ($validator-&gt;isValid($hostname)) {
    // hostname appears to be valid
} else {
    // hostname is invalid; print the reasons
    foreach ($validator-&gt;getMessages() as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            This will match the hostname <var class="varname">$hostname</var> and on failure populate
             <span class="methodname">getMessages()</span> with useful error messages.
        </p>
    </div>

    <div class="section" id="zend.validate.set.hostname.types"><div class="info"><h1 class="title">Validating different types of hostnames</h1></div>
        

        <p class="para">
            You may find you also want to match IP addresses, Local hostnames, or a combination of
            all allowed types. This can be done by passing a parameter to
            <span class="classname">Zend_Validate_Hostname</span> when you instantiate it. The parameter
            should be an integer which determines what types of hostnames are allowed. You are
            encouraged to use the <span class="classname">Zend_Validate_Hostname</span> constants to do
            this.
        </p>

        <p class="para">
            The <span class="classname">Zend_Validate_Hostname</span> constants are:
            <b><tt>ALLOW_DNS</tt></b> to allow only
            <acronym class="acronym">DNS</acronym> hostnames, <b><tt>ALLOW_IP</tt></b> to allow IP addresses,
            <b><tt>ALLOW_LOCAL</tt></b> to allow local network names, and
            <b><tt>ALLOW_ALL</tt></b> to allow all three above types.
        </p>

        <p class="para">
            Additionally there is <b><tt>ALLOW_URI</tt></b> which allows to check hostnames
            according to <a href="http://tools.ietf.org/html/rfc3986" class="link external">&raquo; RFC3986</a>. These
            are registered names which are used by <acronym class="acronym">WINS</acronym>, NetInfo and also local
            hostnames like those defined within your <var class="filename">.hosts</var> file. For security
            reasons <b><tt>ALLOW_URI</tt></b> is not contained within
            <b><tt>ALLOW_ALL</tt></b>.
        </p>

        <p class="para">
            To just check for IP addresses you can use the example below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_IP);
if ($validator-&gt;isValid($hostname)) {
    // hostname appears to be valid
} else {
    // hostname is invalid; print the reasons
    foreach ($validator-&gt;getMessages() as $message) {
        echo &quot;$message\n&quot;;
    }
}
</pre>


        <p class="para">
            As well as using <b><tt>ALLOW_ALL</tt></b> to accept all common hostnames types
            you can combine these types to allow for combinations. For example, to accept
            <acronym class="acronym">DNS</acronym> and Local hostnames instantiate your
            <span class="classname">Zend_Validate_Hostname</span> object as so:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS |
                                        Zend_Validate_Hostname::ALLOW_IP);
</pre>

    </div>

    <div class="section" id="zend.validate.set.hostname.idn"><div class="info"><h1 class="title">Validating International Domains Names</h1></div>
        

        <p class="para">
            Some Country Code Top Level Domains (ccTLDs), such as &#039;de&#039; (Germany), support
            international characters in domain names. These are known as International Domain Names
            (<acronym class="acronym">IDN</acronym>). These domains can be matched by
            <span class="classname">Zend_Validate_Hostname</span> via extended characters that are used in
            the validation process.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>IDN domains</b><br /></span>
            

            <p class="para">
                Until now more than 50 ccTLDs support <acronym class="acronym">IDN</acronym> domains.
            </p>
        </p></blockquote>

        <p class="para">
            To match an <acronym class="acronym">IDN</acronym> domain it&#039;s as simple as just using the standard
            Hostname validator since <acronym class="acronym">IDN</acronym> matching is enabled by default. If you
            wish to disable <acronym class="acronym">IDN</acronym> validation this can be done by either passing a
            parameter to the <span class="classname">Zend_Validate_Hostname</span> constructor or via the
             <span class="methodname">setValidateIdn()</span> method.
        </p>

        <p class="para">
            You can disable <acronym class="acronym">IDN</acronym> validation by passing a second parameter to the
            <span class="classname">Zend_Validate_Hostname</span> constructor in the following way.
        </p>

        <pre class="programlisting brush: php">
$validator =
    new Zend_Validate_Hostname(
        array(
            &#039;allow&#039; =&gt; Zend_Validate_Hostname::ALLOW_DNS,
            &#039;idn&#039;   =&gt; false
        )
    );
</pre>


        <p class="para">
            Alternatively you can either pass <b><tt>TRUE</tt></b> or
            <b><tt>FALSE</tt></b> to  <span class="methodname">setValidateIdn()</span> to enable or
            disable <acronym class="acronym">IDN</acronym> validation. If you are trying to match an
            <acronym class="acronym">IDN</acronym> hostname which isn&#039;t currently supported it is likely it will
            fail validation if it has any international characters in it. Where a ccTLD file doesn&#039;t
            exist in <var class="filename">Zend/Validate/Hostname</var> specifying the additional
            characters a normal hostname validation is performed.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>IDN validation</b><br /></span>
            

            <p class="para">
                Please note that <acronym class="acronym">IDN</acronym>s are only validated if you allow
                <acronym class="acronym">DNS</acronym> hostnames to be validated.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.hostname.tld"><div class="info"><h1 class="title">Validating Top Level Domains</h1></div>
        

        <p class="para">
            By default a hostname will be checked against a list of known <acronym class="acronym">TLD</acronym>s.
            If this functionality is not required it can be disabled in much the same way as
            disabling <acronym class="acronym">IDN</acronym> support. You can disable <acronym class="acronym">TLD</acronym>
            validation by passing a third parameter to the
            <span class="classname">Zend_Validate_Hostname</span> constructor. In the example below we are
            supporting <acronym class="acronym">IDN</acronym> validation via the second parameter.
        </p>

        <pre class="programlisting brush: php">
$validator =
    new Zend_Validate_Hostname(
        array(
            &#039;allow&#039; =&gt; Zend_Validate_Hostname::ALLOW_DNS,
            &#039;idn&#039;   =&gt; true,
            &#039;tld&#039;   =&gt; false
        )
    );
</pre>


        <p class="para">
            Alternatively you can either pass <b><tt>TRUE</tt></b> or
            <b><tt>FALSE</tt></b> to  <span class="methodname">setValidateTld()</span> to enable or
            disable <acronym class="acronym">TLD</acronym> validation.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>TLD validation</b><br /></span>
            

            <p class="para">
                Please note <acronym class="acronym">TLD</acronym>s are only validated if you allow
                <acronym class="acronym">DNS</acronym> hostnames to be validated.
            </p>
        </p></blockquote>
    </div>
</div>
    <div class="section" id="zend.validate.set.iban"><div class="info"><h1 class="title">Iban</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Iban</span> validates if a given value could be a
        <acronym class="acronym">IBAN</acronym> number. <acronym class="acronym">IBAN</acronym> is the abbreviation for
        &quot;International Bank Account Number&quot;.
    </p>

    <div class="section" id="zend.validate.set.iban.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Iban</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Iban</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">locale</span></em>: Sets the locale which is used
                    to get the <acronym class="acronym">IBAN</acronym> format for validation.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.iban.basic"><div class="info"><h1 class="title">IBAN validation</h1></div>
        

        <p class="para">
            <acronym class="acronym">IBAN</acronym> numbers are always related to a country. This means that
            different countries use different formats for their <acronym class="acronym">IBAN</acronym> numbers.
            This is the reason why <acronym class="acronym">IBAN</acronym> numbers always need a locale. By knowing
            this we already know how to use <span class="classname">Zend_Validate_Iban</span>.
        </p>

        <div class="section" id="zend.validate.set.iban.basic.application"><div class="info"><h1 class="title">Application wide locale</h1></div>
            

            <p class="para">
                We could use the application wide locale. This means that when no option is given at
                initiation, <span class="classname">Zend_Validate_Iban</span> searches for the application
                wide locale. See the following code snippet:
            </p>

            <pre class="programlisting brush: php">
// within bootstrap
Zend_Registry::set(&#039;Zend_Locale&#039;, new Zend_Locale(&#039;de_AT&#039;));

// within the module
$validator = new Zend_Validate_Iban();

if ($validator-&gt;isValid(&#039;AT611904300234573201&#039;)) {
    // IBAN appears to be valid
} else {
    // IBAN is not valid
}
</pre>


            <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Application wide locale</b><br /></span>
                

                <p class="para">
                    Of course this works only when an application wide locale was set within the
                    registry previously. Otherwise <span class="classname">Zend_Locale</span> will try to
                    use the locale which the client sends or, when non has been send, it uses the
                    environment locale. Be aware that this can lead to unwanted behaviour within
                    the validation.
                </p>
            </p></blockquote>
        </div>

        <div class="section" id="zend.validate.set.iban.basic.false"><div class="info"><h1 class="title">Ungreedy IBAN validation</h1></div>
            

            <p class="para">
                Sometime it is usefull, just to validate if the given value <em class="emphasis">is</em>
                a <acronym class="acronym">IBAN</acronym> number or not. This means that you don&#039;t want to validate
                it against a defined country. This can be done by using a
                <b><tt>FALSE</tt></b> as locale.
            </p>

            <pre class="programlisting brush: php">
$validator = new Zend_Validate_Iban(array(&#039;locale&#039; =&gt; false));
// Note: you can also set a FALSE as single parameter

if ($validator-&gt;isValid(&#039;AT611904300234573201&#039;)) {
    // IBAN appears to be valid
} else {
    // IBAN is not valid
}
</pre>


            <p class="para">
                So <em class="emphasis">any</em> <acronym class="acronym">IBAN</acronym> number will be valid. Note that
                this should not be done when you accept only accounts from a single country.
            </p>
        </div>

        <div class="section" id="zend.validate.set.iban.basic.aware"><div class="info"><h1 class="title">Region aware IBAN validation</h1></div>
            

            <p class="para">
                To validate against a defined country, you just need to give the wished locale.
                You can do this by the option <span class="property">locale</span> and also afterwards by
                using  <span class="methodname">setLocale()</span>.
            </p>

            <pre class="programlisting brush: php">
$validator = new Zend_Validate_Iban(array(&#039;locale&#039; =&gt; &#039;de_AT&#039;));

if ($validator-&gt;isValid(&#039;AT611904300234573201&#039;)) {
    // IBAN appears to be valid
} else {
    // IBAN is not valid
}
</pre>


            <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Use full qualified locales</b><br /></span>
                

                <p class="para">
                    You must give a full qualified locale, otherwise the country could not be
                    detected correct because languages are spoken in multiple countries.
                </p>
            </p></blockquote>
        </div>
    </div>
</div>
    <div class="section" id="zend.validate.set.identical"><div class="info"><h1 class="title">Identical</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Identical</span> allows you to validate if a given value is
        identical with an set haystack.
    </p>

    <div class="section" id="zend.validate.set.identical.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Identical</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Identical</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">strict</span></em>: Defines if the validation
                    should be done strict. The default value is <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">token</span></em>: Sets the token with which the
                    input will be validated against.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.identical.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            To validate if two values are identical you need to set the origin value as haystack.
            See the following example which validates two strings.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Identical(&#039;origin&#039;);
if ($valid-&gt;isValid($value) {
    return true;
}
</pre>


        <p class="para">
            The validation will only then return <b><tt>TRUE</tt></b> when both values are
            100% identical. In our example, when <var class="varname">$value</var> is &#039;origin&#039;.
        </p>

        <p class="para">
            You can set the wished token also afterwards by using the method
             <span class="methodname">setToken()</span> and  <span class="methodname">getToken()</span> to get
            the actual set token.
        </p>
    </div>

    <div class="section" id="zend.validate.set.identical.types"><div class="info"><h1 class="title">Identical objects</h1></div>
        

        <p class="para">
            Of course <span class="classname">Zend_Validate_Identical</span> can not only validate strings,
            but also any other variable type like Boolean, Integer, Float, Array or even Objects.
            As already noted Haystack and Value must be identical.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Identical(123);
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Type comparison</b><br /></span>
            

            <p class="para">
                You should be aware that also the type of a variable is used for validation.
                This means that the string <em class="emphasis">&#039;3&#039;</em> is not identical with the
                integer <em class="emphasis">3</em>. When you want such a non strict validation you
                must set the <span class="property">strict</span> option.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.identical.formelements"><div class="info"><h1 class="title">Form elements</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Validate_Identical</span> supports also the comparison of form
            elements. This can be done by using the element&#039;s name as <span class="property">token</span>.
            See the following example:
        </p>

        <pre class="programlisting brush: php">
$form-&gt;addElement(&#039;password&#039;, &#039;elementOne&#039;);
$form-&gt;addElement(&#039;password&#039;, &#039;elementTwo&#039;, array(
    &#039;validators&#039; =&gt; array(
        array(&#039;identical&#039;, false, array(&#039;token&#039; =&gt; &#039;elementOne&#039;))
    )
));
</pre>


        <p class="para">
            By using the elements name from the first element as <span class="property">token</span> for the
            second element, the validator validates if the second element is equal with the first
            element. In the case your user does not enter two identical values, you will get an
            validation error.
        </p>
    </div>

    <div class="section" id="zend.validate.set.identical.strict"><div class="info"><h1 class="title">Strict validation</h1></div>
        

        <p class="para">
            As mentioned before <span class="classname">Zend_Validate_Identical</span> validates tokens
            strict. You can change this behaviour by using the <span class="property">strict</span> option.
            The default value for this property is <b><tt>TRUE</tt></b>.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Identical(array(&#039;token&#039; =&gt; 123, &#039;strict&#039; =&gt; FALSE));
$input = &#039;123&#039;;
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            The difference to the previous example is that the validation returns in this case
            <b><tt>TRUE</tt></b>, even if you compare a integer with string value as long
            as the content is identical but not the type.
        </p>

        <p class="para">
            For convinience you can also use  <span class="methodname">setStrict()</span> and
             <span class="methodname">getStrict()</span>.
        </p>
    </div>

    <div class="section" id="zend.validate.set.identical.configuration"><div class="info"><h1 class="title">Configuration</h1></div>
        

        <p class="para">
            As all other validators also <span class="classname">Zend_Validate_Identical</span> supports
            the usage of configuration settings as input parameter. This means that you can
            configure this validator with an <span class="classname">Zend_Config</span> object.
        </p>

        <p class="para">
            But this adds one case which you have to be aware. When you are using an array as
            haystack then you should wrap it within an &#039;<span class="property">token</span>&#039; key when
            it could contain only one element.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Identical(array(&#039;token&#039; =&gt; 123));
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>


        <p class="para">
            The above example validates the integer 123. The reason for this special case is, that
            you can configure the token which has to be used by giving the
            &#039;<span class="property">token</span>&#039; key.
        </p>

        <p class="para">
            So, when your haystack contains one element and this element is named
            &#039;<span class="property">token</span>&#039; then you have to wrap it like shown in the example below.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_Identical(array(&#039;token&#039; =&gt; array(&#039;token&#039; =&gt; 123)));
if ($valid-&gt;isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
</pre>

    </div>
</div>
    <div class="section" id="zend.validate.set.in_array"><div class="info"><h1 class="title">InArray</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_InArray</span> allows you to validate if a given value is
        contained within an array. It is also able to validate multidimensional arrays.
    </p>

    <div class="section" id="zend.validate.set.in_array.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_InArray</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_InArray</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">haystack</span></em>: Sets the haystack for the
                    validation.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">recursive</span></em>: Defines if the validation
                    should be done recursive. This option defaults to <b><tt>FALSE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">strict</span></em>: Defines if the validation
                    should be done strict. This option defaults to <b><tt>FALSE</tt></b>.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.in_array.basic"><div class="info"><h1 class="title">Simple array validation</h1></div>
        

        <p class="para">
            The simplest way, is just to give the array which should be searched against at
            initiation:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_InArray(array(&#039;key&#039; =&gt; &#039;value&#039;,
                                             &#039;otherkey&#039; =&gt; &#039;othervalue&#039;));
if ($validator-&gt;isValid(&#039;value&#039;)) {
    // value found
} else {
    // no value found
}
</pre>


        <p class="para">
            This will behave exactly like <acronym class="acronym">PHP</acronym>&#039;s
             <span class="methodname">in_array()</span> method.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Per default this validation is not strict nor can it validate multidimensional
                arrays.
            </p>
        </p></blockquote>

        <p class="para">
            Of course you can give the array to validate against also afterwards by using the
             <span class="methodname">setHaystack()</span> method.  <span class="methodname">getHaystack()</span>
            returns the actual set haystack array.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_InArray();
$validator-&gt;setHaystack(array(&#039;key&#039; =&gt; &#039;value&#039;, &#039;otherkey&#039; =&gt; &#039;othervalue&#039;));

if ($validator-&gt;isValid(&#039;value&#039;)) {
    // value found
} else {
    // no value found
}
</pre>

    </div>

    <div class="section" id="zend.validate.set.in_array.strict"><div class="info"><h1 class="title">Strict array validation</h1></div>
        

        <p class="para">
            As mentioned before you can also do a strict validation within the array. Per default
            there would be no difference between the integer value <em class="emphasis">0</em> and the
            string <em class="emphasis">&quot;0&quot;</em>. When doing a strict validation this difference will
            also be validated and only same types are accepted.
        </p>

        <p class="para">
            A strict validation can also be done by using two different ways. At initiation and by
            using a method. At initiation you have to give an array with the following structure:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_InArray(
    array(
        &#039;haystack&#039; =&gt; array(&#039;key&#039; =&gt; &#039;value&#039;, &#039;otherkey&#039; =&gt; &#039;othervalue&#039;),
        &#039;strict&#039;   =&gt; true
    )
);

if ($validator-&gt;isValid(&#039;value&#039;)) {
    // value found
} else {
    // no value found
}
</pre>


        <p class="para">
            The <em class="emphasis">haystack</em> key contains your array to validate against. And by
            setting the <em class="emphasis">strict</em> key to <b><tt>TRUE</tt></b>, the validation
            is done by using a strict type check.
        </p>

        <p class="para">
            Of course you can also use the  <span class="methodname">setStrict()</span> method to change
            this setting afterwards and  <span class="methodname">getStrict()</span> to get the actual set
            state.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that the <em class="emphasis">strict</em> setting is per default
                <b><tt>FALSE</tt></b>.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.in_array.recursive"><div class="info"><h1 class="title">Recursive array validation</h1></div>
        

        <p class="para">
            In addition to <acronym class="acronym">PHP</acronym>&#039;s  <span class="methodname">in_array()</span> method
            this validator can also be used to validate multidimensional arrays.
        </p>

        <p class="para">
            To validate multidimensional arrays you have to set the <em class="emphasis">recursive</em>
            option.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_InArray(
    array(
        &#039;haystack&#039; =&gt; array(
            &#039;firstDimension&#039; =&gt; array(&#039;key&#039; =&gt; &#039;value&#039;,
                                      &#039;otherkey&#039; =&gt; &#039;othervalue&#039;),
            &#039;secondDimension&#039; =&gt; array(&#039;some&#039; =&gt; &#039;real&#039;,
                                       &#039;different&#039; =&gt; &#039;key&#039;)),
        &#039;recursive&#039; =&gt; true
    )
);

if ($validator-&gt;isValid(&#039;value&#039;)) {
    // value found
} else {
    // no value found
}
</pre>


        <p class="para">
            Your array will then be validated recursive to see if the given value is contained.
            Additionally you could use  <span class="methodname">setRecursive()</span> to set this option
            afterwards and  <span class="methodname">getRecursive()</span> to retrieve it.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_InArray(
    array(
        &#039;firstDimension&#039; =&gt; array(&#039;key&#039; =&gt; &#039;value&#039;,
                                  &#039;otherkey&#039; =&gt; &#039;othervalue&#039;),
        &#039;secondDimension&#039; =&gt; array(&#039;some&#039; =&gt; &#039;real&#039;,
                                   &#039;different&#039; =&gt; &#039;key&#039;)
    )
);
$validator-&gt;setRecursive(true);

if ($validator-&gt;isValid(&#039;value&#039;)) {
    // value found
} else {
    // no value found
}
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Default setting for recursion</b><br /></span>
            

            <p class="para">
                Per default the recursive validation is turned off.
            </p>
        </p></blockquote>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Option keys within the haystack</b><br /></span>
            

            <p class="para">
                When you are using the keys &#039;<span class="property">haystack</span>&#039;,
                &#039;<span class="property">strict</span>&#039; or &#039;<span class="property">recursive</span>&#039; within your
                haystack, then you must wrap the <span class="property">haystack</span> key.
            </p>
        </p></blockquote>
    </div>
</div>
    <div class="section" id="zend.validate.set.int"><div class="info"><h1 class="title">Int</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Int</span> validates if a given value is an integer. Also
        localized integer values are recognised and can be validated.
    </p>

    <div class="section" id="zend.validate.set.int.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Int</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Int</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">locale</span></em>: Sets the locale which will be
                    used to validate localized integers.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.int.basic"><div class="info"><h1 class="title">Simple integer validation</h1></div>
        

        <p class="para">
            The simplest way to validate an integer is by using the system settings. When no option
            is used, the environment locale is used for validation:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Int();

$validator-&gt;isValid(1234);   // returns true
$validator-&gt;isValid(1234.5); // returns false
$validator-&gt;isValid(&#039;1,234&#039;); // returns true
</pre>


        <p class="para">
            In the above example we expected that our environment is set to &quot;en&quot; as locale. As you
            can see in the third example also grouping is recognised.
        </p>
    </div>

    <div class="section" id="zend.validate.set.int.localized"><div class="info"><h1 class="title">Localized integer validation</h1></div>
        

        <p class="para">
            Often it&#039;s useful to be able to validate also localized values. Integer values are often
            written different in other countries. For example using english you can write &quot;1234&quot; or
            &quot;1,234&quot;. Both are integer values but the grouping is optional. In german for example you
            may write &quot;1.234&quot; and in french &quot;1 234&quot;.
        </p>

        <p class="para">
            <span class="classname">Zend_Validate_Int</span> is able to validate such notations. But it is
            limited to the locale you set. This means that it not simply strips off the separator,
            it validates if the correct separator is used. See the following code:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Int(array(&#039;locale&#039; =&gt; &#039;de&#039;));

$validator-&gt;isValid(1234); // returns true
$validator-&gt;isValid(&quot;1,234&quot;); // returns false
$validator-&gt;isValid(&quot;1.234&quot;); // returns true
</pre>


        <p class="para">
            As you can see, by using a locale, your input is validated localized. Using the english
            notation you get a <b><tt>FALSE</tt></b> when the locale forces a different
            notation.
        </p>

        <p class="para">
            The locale can also be set afterwards by using  <span class="methodname">setLocale()</span> and
            retrieved by using  <span class="methodname">getLocale()</span>.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.ip"><div class="info"><h1 class="title">Ip</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Ip</span> allows you to validate if a given value is an IP
        address. It supports the IPv4 and also the IPv6 standard.
    </p>

    <div class="section" id="zend.validate.set.ip.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Ip</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Ip</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">allowipv4</span></em>: Defines if the validator
                    allows IPv4 adresses. This option defaults to <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">allowipv6</span></em>: Defines if the validator
                    allows IPv6 adresses. This option defaults to <b><tt>TRUE</tt></b>.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.ip.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            A basic example of usage is below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Ip();
if ($validator-&gt;isValid($ip)) {
    // ip appears to be valid
} else {
    // ip is invalid; print the reasons
}
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Invalid IP addresses</b><br /></span>
            

            <p class="para">
                Keep in mind that <span class="classname">Zend_Validate_Ip</span> only validates IP
                addresses. Addresses like &#039;<var class="filename">mydomain.com</var>&#039; or
                &#039;<var class="filename">192.168.50.1/index.html</var>&#039; are no valid
                IP addresses. They are either hostnames or valid <acronym class="acronym">URL</acronym>s but not IP
                addresses.
            </p>
        </p></blockquote>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>IPv6 validation</b><br /></span>
            

            <p class="para">
                <span class="classname">Zend_Validate_Ip</span> validates IPv6 addresses with regex. The
                reason is that the filters and methods from <acronym class="acronym">PHP</acronym> itself don&#039;t
                follow the <acronym class="acronym">RFC</acronym>. Many other available classes also don&#039;t follow
                it.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.ip.singletype"><div class="info"><h1 class="title">Validate IPv4 or IPV6 alone</h1></div>
        

        <p class="para">
            Sometimes it&#039;s useful to validate only one of the supported formats. For example when
            your network only supports IPv4. In this case it would be useless to allow IPv6 within
            this validator.
        </p>

        <p class="para">
            To limit <span class="classname">Zend_Validate_Ip</span> to one protocol you can set the options
            <span class="property">allowipv4</span> or <span class="property">allowipv6</span> to
            <b><tt>FALSE</tt></b>. You can do this either by giving the option to the
            constructor or by using  <span class="methodname">setOptions()</span> afterwards.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Ip(array(&#039;allowipv6&#039; =&gt; false);
if ($validator-&gt;isValid($ip)) {
    // ip appears to be valid ipv4 address
} else {
    // ip is no ipv4 address
}
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Default behaviour</b><br /></span>
            

            <p class="para">
                The default behaviour which <span class="classname">Zend_Validate_Ip</span> follows is to
                allow both standards.
            </p>
        </p></blockquote>
    </div>
</div>
    <div class="section" id="zend.validate.set.isbn"><div class="info"><h1 class="title">Isbn</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_Isbn</span> allows you to validate an
        <acronym class="acronym">ISBN-10</acronym> or <acronym class="acronym">ISBN-13</acronym> value.
    </p>

    <div class="section" id="zend.validate.set.isbn.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Isbn</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Isbn</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">separator</span></em>: Defines the allowed
                    separator for the <acronym class="acronym">ISBN</acronym> number. It defaults to an empty
                    string.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">type</span></em>: Defines the allowed type of
                    <acronym class="acronym">ISBN</acronym> numbers. It defaults to
                    <b><tt>Zend_Validate_Isbn::AUTO</tt></b>. For details take a look at
                    <a href="zend.validate.set.html#zend.validate.set.isbn.type-explicit" class="link">this section</a>.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.isbn.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            A basic example of usage is below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Isbn();
if ($validator-&gt;isValid($isbn)) {
    // isbn is valid
} else {
    // isbn is not valid
}
</pre>


        <p class="para">
            This will validate any <acronym class="acronym">ISBN-10</acronym> and <acronym class="acronym">ISBN-13</acronym> without
            separator.
        </p>
    </div>

    <div class="section" id="zend.validate.set.isbn.type-explicit"><div class="info"><h1 class="title">Setting an explicit ISBN validation type</h1></div>
        

        <p class="para">
            An example of an <acronym class="acronym">ISBN</acronym> type restriction is below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Isbn();
$validator-&gt;setType(Zend_Validate_Isbn::ISBN13);
// OR
$validator = new Zend_Validate_Isbn(array(
    &#039;type&#039; =&gt; Zend_Validate_Isbn::ISBN13,
));

if ($validator-&gt;isValid($isbn)) {
    // this is a valid ISBN-13 value
} else {
    // this is an invalid ISBN-13 value
}
</pre>


        <p class="para">
            The above will validate only <acronym class="acronym">ISBN-13</acronym> values.
        </p>

        <p class="para">
            Valid types include:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para"><b><tt>Zend_Validate_Isbn::AUTO</tt></b> (default)</p>
            </li>

            <li class="listitem">
                <p class="para"><b><tt>Zend_Validate_Isbn::ISBN10</tt></b></p>
            </li>

            <li class="listitem">
                <p class="para"><b><tt>Zend_Validate_Isbn::ISBN13</tt></b></p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.isbn.separator"><div class="info"><h1 class="title">Specifying a separator restriction</h1></div>
        

        <p class="para">
            An example of separator restriction is below:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Isbn();
$validator-&gt;setSeparator(&#039;-&#039;);
// OR
$validator = new Zend_Validate_Isbn(array(
    &#039;separator&#039; =&gt; &#039;-&#039;,
));

if ($validator-&gt;isValid($isbn)) {
    // this is a valid ISBN with separator
} else {
    // this is an invalid ISBN with separator
}
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Values without separator</b><br /></span>
            

            <p class="para">
                This will return <b><tt>FALSE</tt></b> if <var class="varname">$isbn</var> doesn&#039;t
                contain a separator <em class="emphasis">or</em> if it&#039;s an invalid
                <acronym class="acronym">ISBN</acronym> value.
            </p>
        </p></blockquote>

        <p class="para">
            Valid separators include:
        </p>

        <ul class="itemizedlist">
            <li class="listitem"><p class="para">&quot;&quot; (empty) (default)</p></li>
            <li class="listitem"><p class="para">&quot;-&quot; (hyphen)</p></li>
            <li class="listitem"><p class="para">&quot; &quot; (space)</p></li>
        </ul>
    </div>
</div>
    <div class="section" id="zend.validate.set.lessthan"><div class="info"><h1 class="title">LessThan</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_LessThan</span> allows you to validate if a given value is
        less than a maximum border value. It is the cousine of
        <span class="classname">Zend_Validate_GreaterThan</span>.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Zend_Validate_LessThan supports only number validation</b><br /></span>
        

        <p class="para">
            It should be noted that <span class="classname">Zend_Validate_LessThan</span> supports only the
            validation of numbers. Strings or dates can not be validated with this validator.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.lessthan.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_LessThan</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_LessThan</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">max</span></em>: Sets the maximum allowed value.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.lessthan.basic"><div class="info"><h1 class="title">Basic usage</h1></div>
        

        <p class="para">
            To validate if a given value is less than a defined border simply use the following
            example.
        </p>

        <pre class="programlisting brush: php">
$valid  = new Zend_Validate_LessThan(array(&#039;max&#039; =&gt; 10));
$value  = 10;
$return = $valid-&gt;isValid($value);
// returns true
</pre>


        <p class="para">
            The above example returns <b><tt>TRUE</tt></b> for all values which are equal to 10
            or lower than 10.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.notempty"><div class="info"><h1 class="title">NotEmpty</h1></div>
    

    <p class="para">
        This validator allows you to validate if a given value is not empty. This is often useful
        when working with form elements or other user input, where you can use it to ensure required
        elements have values associated with them.
    </p>

    <div class="section" id="zend.validate.set.notempty.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_NotEmpty</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_NotEmpty</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">type</span></em>: Sets the type of validation
                    which will be processed. For details take a look into <a href="zend.validate.set.html#zend.validate.set.notempty.types" class="link">this section</a>.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.notempty.default"><div class="info"><h1 class="title">Default behaviour for Zend_Validate_NotEmpty</h1></div>
        

        <p class="para">
            By default, this validator works differently than you would expect when you&#039;ve worked
            with <acronym class="acronym">PHP</acronym>&#039;s  <span class="methodname">empty()</span> function. In
            particular, this validator will evaluate both the integer <em class="emphasis">0</em> and
            string &#039;<em class="emphasis">0</em>&#039; as empty.
        </p>

        <pre class="programlisting brush: php">
$valid = new Zend_Validate_NotEmpty();
$value  = &#039;&#039;;
$result = $valid-&gt;isValid($value);
// returns false
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Default behaviour differs from PHP</b><br /></span>
            

            <p class="para">
                Without providing configuration, <span class="classname">Zend_Validate_NotEmpty</span>&#039;s
                behaviour differs from <acronym class="acronym">PHP</acronym>.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.notempty.types"><div class="info"><h1 class="title">Changing behaviour for Zend_Validate_NotEmpty</h1></div>
        

        <p class="para">
            Some projects have differing opinions of what is considered an &quot;empty&quot; value: a string
            with only whitespace might be considered empty, or <em class="emphasis">0</em> may be
            considered non-empty (particularly for boolean sequences). To accomodate differing
            needs, <span class="classname">Zend_Validate_NotEmpty</span> allows you to configure which types
            should be validated as empty and which not.
        </p>

        <p class="para">
            The following types can be handled:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis">boolean</em>: Returns <b><tt>FALSE</tt></b> when the
                    boolean value is <b><tt>FALSE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">integer</em>: Returns <b><tt>FALSE</tt></b> when an integer
                    <em class="emphasis">0</em> value is given. Per default this validation is not
                    activated and returns <b><tt>TRUE</tt></b> on any integer values.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">float</em>: Returns <b><tt>FALSE</tt></b> when an float
                    <em class="emphasis">0.0</em> value is given. Per default this validation is not
                    activated and returns <b><tt>TRUE</tt></b> on any float values.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">string</em>: Returns <b><tt>FALSE</tt></b> when an empty
                    string <em class="emphasis">&#039;&#039;</em> is given.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">zero</em>: Returns <b><tt>FALSE</tt></b> when the single
                    character zero (<em class="emphasis">&#039;0&#039;</em>) is given.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">empty_array</em>: Returns <b><tt>FALSE</tt></b> when an
                    empty <em class="emphasis">array</em> is given.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">null</em>: Returns <b><tt>FALSE</tt></b> when an
                    <b><tt>NULL</tt></b> value is given.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">php</em>: Returns <b><tt>FALSE</tt></b> on the same reasons
                    where <acronym class="acronym">PHP</acronym> method  <span class="methodname">empty()</span> would
                    return <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">space</em>: Returns <b><tt>FALSE</tt></b> when an string
                    is given which contains only whitespaces.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">object</em>: Returns <b><tt>TRUE</tt></b>.
                    <b><tt>FALSE</tt></b> will be returned when <span class="property">object</span> is
                    not allowed but an object is given.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">object_string</em>: Returns <b><tt>FALSE</tt></b> when an
                    object is given and it&#039;s  <span class="methodname">__toString()</span> method returns an
                   empty string.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">object_count</em>: Returns <b><tt>FALSE</tt></b> when an
                    object is given, it has an <span class="classname">Countable</span> interface and it&#039;s
                    count is 0.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">all</em>: Returns <b><tt>FALSE</tt></b> on all above types.
                </p>
            </li>
        </ul>

        <p class="para">
            All other given values will return <b><tt>TRUE</tt></b> per default.
        </p>

        <p class="para">
            There are several ways to select which of the above types are validated. You can give
            one or multiple types and add them, you can give an array, you can use constants, or you
            can give a textual string. See the following examples:
        </p>

        <pre class="programlisting brush: php">
// Returns false on 0
$validator = new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::INTEGER);

// Returns false on 0 or &#039;0&#039;
$validator = new Zend_Validate_NotEmpty(
    Zend_Validate_NotEmpty::INTEGER + Zend_NotEmpty::ZERO
);

// Returns false on 0 or &#039;0&#039;
$validator = new Zend_Validate_NotEmpty(array(
    Zend_Validate_NotEmpty::INTEGER,
    Zend_Validate_NotEmpty::ZERO
));

// Returns false on 0 or &#039;0&#039;
$validator = new Zend_Validate_NotEmpty(array(
    &#039;integer&#039;,
    &#039;zero&#039;,
));
</pre>


        <p class="para">
            You can also provide an instance of <span class="classname">Zend_Config</span> to set the
            desired types. To set types after instantiation, use the
             <span class="methodname">setType()</span> method.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.post_code"><div class="info"><h1 class="title">PostCode</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Validate_PostCode</span> allows you to determine if a given value is a
        valid postal code. Postal codes are specific to cities, and in some locales termed
        <acronym class="acronym">ZIP</acronym> codes.
    </p>

    <p class="para">
        <span class="classname">Zend_Validate_PostCode</span> knows more than 160 different postal code
        formates. To select the correct format there are 2 ways. You can either use a fully
        qualified locale or you can set your own format manually.
    </p>

    <p class="para">
        Using a locale is more convenient as Zend Framework already knows the appropriate postal
        code format for each locale; however, you need to use the fully qualified locale (one
        containing a region specifier) to do so. For instance, the locale &quot;de&quot; is a locale but
        could not be used with <span class="classname">Zend_Validate_PostCode</span> as it does not include
        the region; &quot;de_AT&quot;, however, would be a valid locale, as it specifies the region code
        (&quot;AT&quot;, for Austria).
    </p>

    <pre class="programlisting brush: php">
$validator = new Zend_Validate_PostCode(&#039;de_AT&#039;);
</pre>


    <p class="para">
        When you don&#039;t set a locale yourself, then <span class="classname">Zend_Validate_PostCode</span>
        will use the application wide set locale, or, when there is none, the locale returned by
        <span class="classname">Zend_Locale</span>.
    </p>

    <pre class="programlisting brush: php">
// application wide locale within your bootstrap
$locale = new Zend_Locale(&#039;de_AT&#039;);
Zend_Registry::set(&#039;Zend_Locale&#039;, $locale);

$validator = new Zend_Validate_PostCode();
</pre>


    <p class="para">
        You can also change the locale afterwards by calling  <span class="methodname">setLocale()</span>.
        And of course you can get the actual used locale by calling
         <span class="methodname">getLocale()</span>.
    </p>

    <pre class="programlisting brush: php">
$validator = new Zend_Validate_PostCode(&#039;de_AT&#039;);
$validator-&gt;setLocale(&#039;en_GB&#039;);
</pre>


    <p class="para">
        Postal code formats themself are simply regular expression strings. When the international
        postal code format, which is used by setting the locale, does not fit your needs, then you
        can also manually set a format by calling  <span class="methodname">setFormat()</span>.
    </p>

    <pre class="programlisting brush: php">
$validator = new Zend_Validate_PostCode(&#039;de_AT&#039;);
$validator-&gt;setFormat(&#039;AT-\d{5}&#039;);
</pre>


    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Conventions for self defined formats</b><br /></span>
        

        <p class="para">
            When using self defined formats you should omit the starting (<strong class="command">&#039;/^&#039;</strong>)
            and ending tags (<strong class="command">&#039;$/&#039;</strong>). They are attached automatically.
        </p>

        <p class="para">
            You should also be aware that postcode values are always be validated in a strict way.
            This means that they have to be written standalone without additional characters when
            they are not covered by the format.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.post_code.constructor"><div class="info"><h1 class="title">Constructor options</h1></div>
        

        <p class="para">
            At it&#039;s most basic, you may pass either a <span class="classname">Zend_Locale</span> object or a
            string representing a fully qualified locale to the constructor of
            <span class="classname">Zend_Validate_PostCode</span>.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_PostCode(&#039;de_AT&#039;);
$validator = new Zend_Validate_PostCode($locale);
</pre>


        <p class="para">
            Additionally, you may pass either an array or a <span class="classname">Zend_Config</span>
            object to the constructor. When you do so, you must include either the key &quot;locale&quot; or
            &quot;format&quot;; these will be used to set the appropriate values in the validator object.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_PostCode(array(
    &#039;locale&#039; =&gt; &#039;de_AT&#039;,
    &#039;format&#039; =&gt; &#039;AT_\d+&#039;
));
</pre>

    </div>

    <div class="section" id="zend.validate.set.post_code.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_PostCode</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_PostCode</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">format</span></em>: Sets a postcode format which
                    will be used for validation of the input.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">locale</span></em>: Sets a locale from which the
                    postcode will be taken from.
                </p>
            </li>
        </ul>
    </div>
</div>
    <div class="section" id="zend.validate.set.regex"><div class="info"><h1 class="title">Regex</h1></div>
    

    <p class="para">
        This validator allows you to validate if a given string conforms a defined regular
        expression.
    </p>

    <div class="section" id="zend.validate.set.regex.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Regex</h1></div>
        

        <p class="para">
            The following options are supported for <span class="classname">Zend_Validate_Regex</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">pattern</span></em>: Sets the regular expression
                    pattern for this validator.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.regex.basic"><div class="info"><h1 class="title">Validation with Zend_Validate_Regex</h1></div>
        

        <p class="para">
            Validation with regular expressions allows to have complicated validations being done
            without writing a own validator. The usage of regular expression is quite common and
            simple. Let&#039;s look at some examples:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Regex(array(&#039;pattern&#039; =&gt; &#039;/^Test/&#039;);

$validator-&gt;isValid(&quot;Test&quot;); // returns true
$validator-&gt;isValid(&quot;Testing&quot;); // returns true
$validator-&gt;isValid(&quot;Pest&quot;); // returns false
</pre>


        <p class="para">
            As you can see, the pattern has to be given using the same syntax as for
             <span class="methodname">preg_match()</span>. For details about regular expressions take a look
            into <a href="http://php.net/manual/en/reference.pcre.pattern.syntax.php" class="link external">&raquo; PHP&#039;s
                manual about PCRE pattern syntax</a>.
        </p>
    </div>

    <div class="section" id="zend.validate.set.regex.handling"><div class="info"><h1 class="title">Pattern handling</h1></div>
        

        <p class="para">
            It is also possible to set a different pattern afterwards by using
             <span class="methodname">setPattern()</span> and to get the actual set pattern with
             <span class="methodname">getPattern()</span>.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_Regex(array(&#039;pattern&#039; =&gt; &#039;/^Test/&#039;);
$validator-&gt;setPattern(&#039;ing$/&#039;);

$validator-&gt;isValid(&quot;Test&quot;); // returns false
$validator-&gt;isValid(&quot;Testing&quot;); // returns true
$validator-&gt;isValid(&quot;Pest&quot;); // returns false
</pre>

    </div>
</div>
    <div class="section" id="zend.validate.sitemap"><div class="info"><h1 class="title">Sitemap Validators</h1></div>
    

    <p class="para">
        The following validators conform to the <a href="http://www.sitemaps.org/protocol.php" class="link external">&raquo; Sitemap <acronym class="acronym">XML</acronym>
            protocol</a>.
    </p>

    <div class="section" id="zend.validate.sitemap.changefreq"><div class="info"><h1 class="title">Sitemap_Changefreq</h1></div>
        

        <p class="para">
            Validates whether a string is valid for using as a &#039;changefreq&#039;
            element in a Sitemap <acronym class="acronym">XML</acronym> document. Valid values are: &#039;always&#039;,
            &#039;hourly&#039;, &#039;daily&#039;, &#039;weekly&#039;, &#039;monthly&#039;, &#039;yearly&#039;, or &#039;never&#039;.
        </p>

        <p class="para">
            Returns <b><tt>TRUE</tt></b> if and only if the value is a string
            and is equal to one of the frequencies specified above.
        </p>
    </div>

    <div class="section" id="zend.validate.sitemap.lastmod"><div class="info"><h1 class="title">Sitemap_Lastmod</h1></div>
        

        <p class="para">
            Validates whether a string is valid for using as a &#039;lastmod&#039;
            element in a Sitemap <acronym class="acronym">XML</acronym> document. The lastmod element should
            contain a <acronym class="acronym">W3C</acronym> date string, optionally discarding information
            about time.
        </p>

        <p class="para">
            Returns <b><tt>TRUE</tt></b> if and only if the given value is
            a string and is valid according to the protocol.
        </p>

        <div class="example" id="zend.validate.sitemap.lastmod.example"><div class="info"><p><b>Example #1 Sitemap Lastmod Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$validator = new Zend_Validate_Sitemap_Lastmod();

$validator-&gt;isValid(&#039;1999-11-11T22:23:52-02:00&#039;); // true
$validator-&gt;isValid(&#039;2008-05-12T00:42:52+02:00&#039;); // true
$validator-&gt;isValid(&#039;1999-11-11&#039;); // true
$validator-&gt;isValid(&#039;2008-05-12&#039;); // true

$validator-&gt;isValid(&#039;1999-11-11t22:23:52-02:00&#039;); // false
$validator-&gt;isValid(&#039;2008-05-12T00:42:60+02:00&#039;); // false
$validator-&gt;isValid(&#039;1999-13-11&#039;); // false
$validator-&gt;isValid(&#039;2008-05-32&#039;); // false
$validator-&gt;isValid(&#039;yesterday&#039;); // false
</pre>

        </div>
    </div>

    <div class="section" id="zend.validate.sitemap.loc"><div class="info"><h1 class="title">Sitemap_Loc</h1></div>
        

        <p class="para">
            Validates whether a string is valid for using as a &#039;loc&#039;
            element in a Sitemap <acronym class="acronym">XML</acronym> document. This uses
             <span class="methodname">Zend_Form::check()</span> internally. Read more at
            <a href="zend.uri.chapter.html#zend.uri.validation" class="link">URI Validation</a>.
        </p>
    </div>

    <div class="section" id="zend.validate.sitemap.priority"><div class="info"><h1 class="title">Sitemap_Priority</h1></div>
        

        <p class="para">
            Validates whether a value is valid for using as a &#039;priority&#039;
            element in a Sitemap <acronym class="acronym">XML</acronym> document. The value should be a
            decimal between 0.0 and 1.0. This validator accepts both numeric
            values and string values.
        </p>

        <div class="example" id="zend.validate.sitemap.priority.example"><div class="info"><p><b>Example #2 Sitemap Priority Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$validator = new Zend_Validate_Sitemap_Priority();

$validator-&gt;isValid(&#039;0.1&#039;); // true
$validator-&gt;isValid(&#039;0.789&#039;); // true
$validator-&gt;isValid(0.8); // true
$validator-&gt;isValid(1.0); // true

$validator-&gt;isValid(&#039;1.1&#039;); // false
$validator-&gt;isValid(&#039;-0.4&#039;); // false
$validator-&gt;isValid(1.00001); // false
$validator-&gt;isValid(0xFF); // false
$validator-&gt;isValid(&#039;foo&#039;); // false
</pre>

        </div>
    </div>

    <div class="section" id="zend.validate.set.sitemap.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_Sitemap_*</h1></div>
        

        <p class="para">
            There are no supported options for any of the Sitemap validators.
        </p>
    </div>
</div>
    <div class="section" id="zend.validate.set.stringlength"><div class="info"><h1 class="title">StringLength</h1></div>
    

    <p class="para">
        This validator allows you to validate if a given string is between a defined length.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Zend_Validate_StringLength supports only string validation</b><br /></span>
        

        <p class="para">
            It should be noted that <span class="classname">Zend_Validate_StringLength</span> supports only
            the validation of strings. Integers, floats, dates or objects can not be validated with
            this validator.
        </p>
    </p></blockquote>

    <div class="section" id="zend.validate.set.stringlength.options"><div class="info"><h1 class="title">Supported options for Zend_Validate_StringLength</h1></div>
        

        <p class="para">
            The following options are supported for
            <span class="classname">Zend_Validate_StringLength</span>:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">encoding</span></em>: Sets the
                    <b><tt>ICONV</tt></b> encoding which has to be used for this string.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">min</span></em>: Sets the minimum allowed length
                    for a string.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><span class="property">max</span></em>: Sets the maximum allowed length
                    for a string.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.validate.set.stringlength.basic"><div class="info"><h1 class="title">Default behaviour for Zend_Validate_StringLength</h1></div>
        

        <p class="para">
            Per default this validator checks if a value is between <span class="property">min</span> and
            <span class="property">max</span>. But for <span class="property">min</span> the default value is
            <em class="emphasis">0</em> and for <span class="property">max</span> it is
            <em class="emphasis"><b><tt>NULL</tt></b></em> which means unlimited.
        </p>

        <p class="para">
            So per default, without giving any options, this validator only checks if the input
            is a string.
        </p>
    </div>

    <div class="section" id="zend.validate.set.stringlength.maximum"><div class="info"><h1 class="title">Limiting the maximum allowed length of a string</h1></div>
        

        <p class="para">
            To limit the maximum allowed length of a string you need to set the
            <span class="property">max</span> property. It accepts an integer value as input.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_StringLength(array(&#039;max&#039; =&gt; 6));

$validator-&gt;isValid(&quot;Test&quot;); // returns true
$validator-&gt;isValid(&quot;Testing&quot;); // returns false
</pre>


        <p class="para">
            You can set the maximum allowed length also afterwards by using the
             <span class="methodname">setMax()</span> method. And  <span class="methodname">getMax()</span> to
            retrieve the actual maximum border.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_StringLength();
$validator-&gt;setMax(6);

$validator-&gt;isValid(&quot;Test&quot;); // returns true
$validator-&gt;isValid(&quot;Testing&quot;); // returns false
</pre>

    </div>

    <div class="section" id="zend.validate.set.stringlength.minimum"><div class="info"><h1 class="title">Limiting the minimal required length of a string</h1></div>
        

        <p class="para">
            To limit the minimal required length of a string you need to set the
            <span class="property">min</span> property. It accepts also an integer value as input.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_StringLength(array(&#039;min&#039; =&gt; 5));

$validator-&gt;isValid(&quot;Test&quot;); // returns false
$validator-&gt;isValid(&quot;Testing&quot;); // returns true
</pre>


        <p class="para">
            You can set the minimal requested length also afterwards by using the
             <span class="methodname">setMin()</span> method. And  <span class="methodname">getMin()</span> to
            retrieve the actual minimum border.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_StringLength();
$validator-&gt;setMin(5);

$validator-&gt;isValid(&quot;Test&quot;); // returns false
$validator-&gt;isValid(&quot;Testing&quot;); // returns true
</pre>

    </div>

    <div class="section" id="zend.validate.set.stringlength.both"><div class="info"><h1 class="title">Limiting a string on both sides</h1></div>
        

        <p class="para">
            Sometimes it is required to get a string which has a maximal defined length but which
            is also minimal chars long. For example when you have a textbox where a user can enter
            his name, then you may want to limit the name to maximum 30 chars but want to get sure
            that he entered his name. So you limit the mimimum required length to 3 chars. See the
            following example:
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_StringLength(array(&#039;min&#039; =&gt; 3, &#039;max&#039; =&gt; 30));

$validator-&gt;isValid(&quot;.&quot;); // returns false
$validator-&gt;isValid(&quot;Test&quot;); // returns true
$validator-&gt;isValid(&quot;Testing&quot;); // returns true
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Setting a lower maximum border than the minimum border</b><br /></span>
            

            <p class="para">
                When you try to set a lower maximum value as the actual minimum value, or a
                higher minimum value as the actual maximum value, then an exception will be
                raised.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.validate.set.stringlength.encoding"><div class="info"><h1 class="title">Encoding of values</h1></div>
        

        <p class="para">
            Strings are always using a encoding. Even when you don&#039;t set the encoding explicit,
            <acronym class="acronym">PHP</acronym> uses one. When your application is using a different encoding
            than <acronym class="acronym">PHP</acronym> itself then you should set an encoding yourself.
        </p>

        <p class="para">
            You can set your own encoding at initiation with the <span class="property">encoding</span>
            option, or by using the  <span class="methodname">setEncoding()</span> method. We assume that
            your installation uses <acronym class="acronym">ISO</acronym> and your application it set to
            <acronym class="acronym">ISO</acronym>. In this case you will see the below behaviour.
        </p>

        <pre class="programlisting brush: php">
$validator = new Zend_Validate_StringLength(
    array(&#039;min&#039; =&gt; 6)
);
$validator-&gt;isValid(&quot;Ärger&quot;); // returns false

$validator-&gt;setEncoding(&quot;UTF-8&quot;);
$validator-&gt;isValid(&quot;Ärger&quot;); // returns true

$validator2 = new Zend_Validate_StringLength(
    array(&#039;min&#039; =&gt; 6, &#039;encoding&#039; =&gt; &#039;UTF-8&#039;)
);
$validator2-&gt;isValid(&quot;Ärger&quot;); // returns true
</pre>


        <p class="para">
            So when your installation and your application are using different encodings, then you
            should always set an encoding yourself.
        </p>
    </div>
</div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.validate.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.validate.html">Zend_Validate</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.validate.validator_chains.html">Validator Chains</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.validate.html">Zend_Validate</a></li>
  <li><a href="zend.validate.introduction.html">Introduction</a></li>
  <li class="active"><a href="zend.validate.set.html">Standard Validation Classes</a></li>
  <li><a href="zend.validate.validator_chains.html">Validator Chains</a></li>
  <li><a href="zend.validate.writing_validators.html">Writing Validators</a></li>
  <li><a href="zend.validate.messages.html">Validation Messages</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>